f



Ruby 1.8.0 and Mac OS X and Tcl/Tk 8.4 Aqua (not!)

My trials with Ruby and Tcl/Tk on Mac OS X

  Ruby is 1.8.0 preview 7
  Tcl/Tk 8.4 is the recent TclTk-Aqua build for that native OSX Aqua look
  Mac OS X is 10.2.3

(1) 'configure' wasn't finding Tcl/Tk, so I hacked up an OSX-only version
    of ext/tcltklib/extconf.rb with hard-coded parameters 
    (which might be OK because of the frameworks)

  =========
  # extconf.rb for tcltklib
  # HACKED for Mac OS X !!!
  
  require 'mkmf'
 
  if RUBY_PLATFORM !~ /mswin32|mingw|cygwin|bccwin32/
    have_library("nsl", "t_open")
    have_library("socket", "socket")
    have_library("dl", "dlopen")
    have_library("m", "log") 
  end
  
  # these are left-over; they mean nothing
  dir_config("tk")
  dir_config("tcl")
  dir_config("X11")
  
  tklib = with_config("tklib")
  tcllib = with_config("tcllib")
  stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")

  stubs = true                  # force it

  $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
  $CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM

  # these two are needed because #include <tcl.h> isn't "framework" friendly
  $CPPFLAGS += ' -I/Library/Frameworks/Tcl.framework/Headers'
  $CPPFLAGS += ' -I/Library/Frameworks/Tk.framework/Headers'

  # tell the compiler where the libraries are
  $CPPFLAGS += ' -framework Tcl -framework Tk'

  # let the linker know where the libraries are
  $LDFLAGS += ' -framework Tcl -framework Tk'

  create_makefile("tcltklib")
  =========

  You should be thoroughly disgusted with that.  However, I was getting
  tired of running the following, and didn't know how to get the top-level 
  'make' to add all those options when it configured the extension.
  Would those options really get carried from the top-level "./configure"
  all the way down to the extension?

        ruby extconf.rb \
         --with-tcl-include=/Library/Frameworks/Tcl.framework/Headers \
         --with-tk-include=/Library/Frameworks/Tk.framework/Headers \
         --with-tcl-lib=/Library/Frameworks/Tcl.framework/Tcl \
         --with-tk-lib=/Library/Frameworks/Tk.framework/Tk \
         --enable-tcltk_stubs --enable-tk_stubs

(2) Now, the extension gets configured and compiles OK.
    Run-time is something else.  

      /usr/lib/ruby/1.6/tk.rb:7:in `require': tcltklib: tcltk_stubs init error(-1) (LoadError)

    Debug printfs revealed that the stubs interface was looking for 
    a library of 'libtcl8.4.bundle'.  That's no-good for several reasons:
        - the Tcl and Tk libraries do not have a 'bundle' extension (DLEXT)
        - their names are much different than that

    I worked around this mismatch by defining two environment variables,
    thanks to the clear foresight of the author of 'stubs.c'!

        export RUBY_TCL_DLL=/Library/Frameworks/Tcl.framework/Tcl
        export RUBY_TK_DLL=/Library/Frameworks/Tk.framework/Tk

(3) Now, when loading the 'tcltklib' extension, there was a new error:

        /usr/lib/ruby/1.6/tk.rb:7:in `require': tcltklib: tcltk_stubs init error(-2) (LoadError)

    The code showed that it couldn't find 'Tcl_CreateInterp'.
    After digging around 'dln.c' and the 'dl' library, I noticed a
    routine called 'dlsym_auto_underscore'.  In the '#define' for DLSYM
    I used it instead of 'dlsym'.  It seems to work, since the extension
    now loads without complaint.

(4) So, I run 'demo/lines1.rb', and a big window comes up, with the
    translucent blue button in the Aqua style that says 'Draw'.  Looks good, 
    but there are a few problems:

        - every click in the window gives:  "SetFrontProcess failed, -606"
        - the window cannot be dragged
        - the window cannot be closed, neither from the title bar, 
          nor with a ^ or ^\ from the shell (a 'kill' from another window
          works OK, though)

(5) According to some Apple documents, the correct macros to detect
    Mac OS X are both __DARWIN__ and __APPLE__.  In some places (dln.c)
    I see NeXT and __APPLE__, or else it assumes OPENSTEP.  I doubt that's 
    a problem, but it had me looking cross-eyed at it for a long time!  :-)

FWIW, the top-level 'configure' generates: HAVE_LIBDL, HAVE_DLOPEN,
and a DLEXT of ".bundle"

So, I hope all this rambling will help someone else figure out what's going on.



0
mghall (9)
8/2/2003 7:12:31 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

3 Replies
740 Views

Similar Articles

[PageSpeed] 30

On Saturday, August 2, 2003, at 03:21 PM, Mike Hall wrote:

>
> My trials with Ruby and Tcl/Tk on Mac OS X
> [snip]

Only once was I able to get tcltk working on Mac OS X and, 
unfortunately, I did not document how I did it and have never been able 
to repeat it (I have learned from that mistake :-( . I do hope that 
someone, somewhere, can figure this out, document what they did and 
share it with others.

Regards,

Mark


0
mwilson13 (130)
8/2/2003 8:38:49 PM
Hi, 

From: Mike Hall <mghall@enteract.com>
Subject: Ruby 1.8.0 and Mac OS X and Tcl/Tk 8.4 Aqua (not!)
Date: Sun, 3 Aug 2003 04:21:58 +0900
Message-ID: <bgh2ev$h8m$2@bob.news.rcn.net>
> My trials with Ruby and Tcl/Tk on Mac OS X
    (snip)
> (4) So, I run 'demo/lines1.rb', and a big window comes up, with the
>     translucent blue button in the Aqua style that says 'Draw'.  Looks good, 
>     but there are a few problems:
> 
>         - every click in the window gives:  "SetFrontProcess failed, -606"
>         - the window cannot be dragged
>         - the window cannot be closed, neither from the title bar, 
>           nor with a ^ or ^\ from the shell (a 'kill' from another window
>           works OK, though)

I read sources for MacOS X on Tcl/Tk8.4.4. But I couldn't understand 
the reason of the trouble. Although I thought that the trouble is based 
on the fail to treat events properly, I couldn't find the code which is 
the reason of the trouble. 
I have no chance to use MacOS X. So I cannot test to find the reason. 
I have not enough time to fix the trouble before Ruby 1.8.0 release. 
I'm sorry but I'll not modify sources on Ruby1.8.0-release. 
-- 
                                  Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

0
nagai (573)
8/3/2003 2:52:30 AM
> I read sources for MacOS X on Tcl/Tk8.4.4. But I couldn't understand
> the reason of the trouble. Although I thought that the trouble is based
> on the fail to treat events properly, I couldn't find the code which is
> the reason of the trouble.

Probably because you don't have access to that code. :) I went down 
this path with RubyCocoa a while back. If I recall correctly, if you 
want to handle UI events in Mac OS X, the executable must reside within 
an application package/bundle. I filed a bug with Apple at the time, 
but I don't know the current status (ie, whether or not this has 
changed in Panther).

Chris

On Saturday, August 2, 2003, at 7:52 PM, Hidetoshi NAGAI wrote:

> Hi,
>
> From: Mike Hall <mghall@enteract.com>
> Subject: Ruby 1.8.0 and Mac OS X and Tcl/Tk 8.4 Aqua (not!)
> Date: Sun, 3 Aug 2003 04:21:58 +0900
> Message-ID: <bgh2ev$h8m$2@bob.news.rcn.net>
>> My trials with Ruby and Tcl/Tk on Mac OS X
>     (snip)
>> (4) So, I run 'demo/lines1.rb', and a big window comes up, with the
>>     translucent blue button in the Aqua style that says 'Draw'.  
>> Looks good,
>>     but there are a few problems:
>>
>>         - every click in the window gives:  "SetFrontProcess failed, 
>> -606"
>>         - the window cannot be dragged
>>         - the window cannot be closed, neither from the title bar,
>>           nor with a ^ or ^\ from the shell (a 'kill' from another 
>> window
>>           works OK, though)
>
> I read sources for MacOS X on Tcl/Tk8.4.4. But I couldn't understand
> the reason of the trouble. Although I thought that the trouble is based
> on the fail to treat events properly, I couldn't find the code which is
> the reason of the trouble.
> I have no chance to use MacOS X. So I cannot test to find the reason.
> I have not enough time to fix the trouble before Ruby 1.8.0 release.
> I'm sorry but I'll not modify sources on Ruby1.8.0-release.
> -- 
>                                   Hidetoshi NAGAI 
> (nagai@ai.kyutech.ac.jp)
>


0
chris2085 (12)
8/3/2003 4:45:16 AM
Reply: