Log in

No account? Create an account

gtk-sharp on os x without x11

« previous entry | next entry »
Oct. 21st, 2006 | 11:53 pm

I've achieved some success getting mono and gtk to run on my OS X laptop. I ended up grabbing mono- off of the daily snapshots, and then discovered that I needed a small "hackish" patch from Allan Hsu on the mono-osx list in order to get it to build correctly.

Index: libgc/darwin_stop_world.c
--- libgc/darwin_stop_world.c (revision 65895)
+++ libgc/darwin_stop_world.c (working copy)
@@ -92,9 +92,11 @@
lo = GC_approx_sp();
} else {
/* Get the thread state (registers, etc) */
+ /* MACHINE_THREAD_STATE is broken in the new 10.4u SDK that comes with XCode 2.4 */
r = thread_get_state(
+ 1,
if(r != KERN_SUCCESS) ABORT("thread_get_state failed");
@@ -193,7 +195,7 @@
ppc_thread_state64_t info;
# endif
mach_msg_type_number_t outCount = THREAD_STATE_MAX;
- r = thread_get_state(thread, MACHINE_THREAD_STATE,
+ r = thread_get_state(thread, 1,
(natural_t *)&info, &outCount);
if(r != KERN_SUCCESS) continue;

@@ -236,7 +238,7 @@
WARN("This is completely untested and likely will not work\n", 0);
i386_thread_state_t info;
mach_msg_type_number_t outCount = THREAD_STATE_MAX;
- r = thread_get_state(thread, MACHINE_THREAD_STATE,
+ r = thread_get_state(thread, 1,
(natural_t *)&info, &outCount);
if(r != KERN_SUCCESS) continue;

Index: libgc/os_dep.c
--- libgc/os_dep.c (revision 65895)
+++ libgc/os_dep.c (working copy)
@@ -3702,7 +3702,7 @@
+ 1
if(r != KERN_SUCCESS) ABORT("task_set_exception_ports failed");

However I also wanted to use a native version of GTK instead of the one running through X11 (as X11 apps on OS X are kind of second class citizens. I managed to find the gtk+ for Mac OS X project which provided a rather nice build-gtk.sh script which handled grabbing all the dependencies and building GTK.

Finally I needed to link mono to gtk so I needed to build gtk-sharp, alas version 2.8.3 kept dying on me with some segfault in the gtk_init function. Thankfully when I pulled it out from the mono anonymous subversion archive:


today, it built.

I had a few problems getting mono to find the right libraries, the global assembly cache thought that gtk-sharp depended on gtk-x11.2.0.0.dylib, and I needed to edit lib/mono/gac/gtk-sharp/*/gtk-sharp.dll.config to include:

<dllmap dll="libgtk-x11.2.0-0.dll" target="libgtk-quartz-2.0.0.dylib"/>

Then I needed to update LD_LIBRARY_PATH to include /opt/gtk/lib (which was the default install path path used by the build-gtk.sh script.)

After doing all that the gtk-sharp samples ran mostly correctly.

I think I like that dllmap feature. It seems rather convienent to be able remap a dependency through a text file. Also the way that "assemblies" are named includes a cryptographic id as part of the name which makes it really easy to prevent name collisions between different versions of libraries with the same "human" name.

Next I want to get a slightly more mono friendly version of IronPython called FePy installed, and then see how to call C code from mono.
Tags: , ,

Link | Leave a comment | Share

Comments {3}

gtk-sharp compiling

from: jimmy_sk8a
date: Jan. 1st, 2008 11:11 am (UTC)

happy new year to you,

yesterday i gave gtk native a try and followed your post.. now i got stock while compiling gtk-sharp. all the gtk+ stuff went well, and a gtk demo app also running without X11.

can you give me some hints how do you compiled gtk-sharp that it took the right files from the native gtk? i added the paths (/opt/gtk/lib/pkgconfig/) to the pkg_config_path variable. i thought asking here would probably be the easier way, because of the same circumstances.


thank you

Reply | Thread

Diane Trout

Re: gtk-sharp compiling

from: alienghic
date: Jan. 2nd, 2008 12:26 am (UTC)

Is there any mono*.pc in /opt/gtk/lib/pkgconfig? (Or maybe somewhere else?)

My guess is that the mono package config file is hiding somewhere in the mono install)

Reply | Parent | Thread

Re: gtk-sharp compiling

from: jimmy_sk8a
date: Jan. 2nd, 2008 10:47 am (UTC)

it was because of two different versions of pkgconfig and wrong path to them. now it works great, my first native gtk# is already running :) thanks to you!

Reply | Parent | Thread