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

**URL:** <https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188>\
**Category:** ruby-talk\
**Created:** [2 August 2003 19:21 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188 "2003-08-02T19:21:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike4](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mike4](https://rubytalk.org/u/Mike4)\
**Post date:** [2 August 2003 19:21 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188/1 "2003-08-02T19:21:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mark\_Wilson](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mark\_Wilson](https://rubytalk.org/u/Mark_Wilson)\
**Post date:** [2 August 2003 20:38 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188/2 "2003-08-02T20:38:49Z")

</div>

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

> **···**
>
> On Saturday, August 2, 2003, at 03:21 PM, Mike Hall wrote:
> 
> > My trials with Ruby and Tcl/Tk on Mac OS X  
> > [snip]

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://rubytalk.org/u/Hidetoshi_NAGAI)\
**Post date:** [3 August 2003 02:52 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188/3 "2003-08-03T02:52:30Z")

</div>

Hi,

> **···**
>
> From: Mike Hall [mghall@enteract.com](mailto: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](mailto: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)
> 
> ```

---

<div class="post-metadata">

**Author:** ![Chris\_Thomas](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@Chris\_Thomas](https://rubytalk.org/u/Chris_Thomas)\
**Post date:** [3 August 2003 04:45 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188/4 "2003-08-03T04:45:16Z")

</div>

> 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](mailto: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](mailto: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)

---

<div class="post-metadata">

**Author:** ![Mark\_Wilson](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mark\_Wilson](https://rubytalk.org/u/Mark_Wilson)\
**Post date:** [3 August 2003 13:39 UTC](https://rubytalk.org/t/ruby-1-8-0-and-mac-os-x-and-tcl-tk-8-4-aqua-not/7188/5 "2003-08-03T13:39:21Z")

</div>

I think that once the problem is solved, it can be released as a shim  
prior to the release of 1.8.1. For your information, here is a link to  
a page describing how Python gets Tkinter to work on Mac OS X:

[http://tony.lownds.com/macosx/tkinter.html](http://tony.lownds.com/macosx/tkinter.html)

I would be happy to help with this effort. My abilities are very  
limited in this area, but I can test possible solutions and report the  
results.

Regards,

Mark

> **···**
>
> On Saturday, August 2, 2003, at 10:52 PM, Hidetoshi NAGAI wrote:
> 
> > [snip]  
> > I’m sorry but I’ll not modify sources on Ruby1.8.0-release.
