Mac OS X Leopart (v10.5) で glib をビルドする

前回 Linux でやったように Mac で glib のデバッグ版をビルドしようと configure したらこけたので、いろいろ調べたところ以下のようにしたらできた。

$ ./configure CFLAGS="-I/opt/local/include -L/opt/local/lib -g"

ところで、Mac ではコンパイル時と実行時に指定する共有ライブラリのパスが同じじゃないとダメみたいだ。Linux だと違っても問題なかったのに、なんでかねぇ。

gcc -o sample sample.c `pkg-config --cflags glib-2.0` -L/Users/.../glib-2.16.5/glib/.libs -lglib-2.0

実行するときは環境変数 DYLD_LIBRARY_PATH にデバッグ版のパスを指定する。Linux と Mac ではライブラリの探索パスの環境変数が違うので注意。実はさっき知ったんだけど。

$ DYLD_LIBRARY_PATH=/Users/.../glib-2.16.5/glib/.libs/ gdb ./sample

gdbソースコードを追うと、こんな感じになる。

$ DYLD_LIBRARY_PATH=/Users/.../glib-2.16.5/glib/.libs/ gdb ./sample
GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct  2 04:07:49 UTC 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared libraries .... done

(gdb) run
Starting program: /Users/.../sample 
Reading symbols for shared libraries +++............................................................................... done
Reading symbols for shared libraries . done
Starting loop...
^C
Program received signal SIGINT, Interrupt.
0x907b05e2 in select$DARWIN_EXTSN ()
(gdb) i s
#0  0x907b05e2 in select$DARWIN_EXTSN ()
#1  0x00149850 in g_poll (fds=0x0, nfds=0, timeout=-1) at gmain.c:512
#2  0x0014ea32 in g_main_context_poll (context=0x406bb0, timeout=-1, priority=2147483647, fds=0x0, n_fds=0) at gmain.c:2954
#3  0x0014ddc5 in g_main_context_iterate (context=0x406bb0, block=1, dispatch=1, self=0x406fd0) at gmain.c:2640
#4  0x0014e5f3 in g_main_loop_run (loop=0x406f40) at gmain.c:2853
#5  0x00001fe3 in main ()
(gdb) up 2
#2  0x0014ea32 in g_main_context_poll (context=0x406bb0, timeout=-1, priority=2147483647, fds=0x0, n_fds=0) at gmain.c:2954
2954	      if *1;
(gdb)

*1:*poll_func) (fds, n_fds, timeout) < 0 && errno != EINTR) (gdb) list 2949 LOCK_CONTEXT (context); 2950 2951 poll_func = context->poll_func; 2952 2953 UNLOCK_CONTEXT (context); 2954 if ((*poll_func) (fds, n_fds, timeout) < 0 && errno != EINTR) 2955 { 2956 #ifndef G_OS_WIN32 2957 g_warning ("poll(2) failed due to: %s.", 2958 g_strerror (errno