can't load .so/.DLL -- GHCi on MacOSX [SOLVED]
これの続き。
単に MacPortsでdlcompatというライブラリをインストールすれば解決した。
port -d -v install dlcompat
私の環境では、ビルドは途中で失敗したが、
dlfcn.c:819: warning: Pragma CALL_ON_LOAD is deprecated; use constructor attribute instead ... /usr/bin/gcc-4.0 -dynamiclib -o libdl.1.dylib dlfcn.o -install_name /opt/local/lib/libdl.1.dylib -compatibility_version 1 -current_version 1 Undefined symbols: "_dlcompat_init_func", referenced from: initializer$0 in dlfcn.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [libdl.1.dylib] Error 1
展開されたソースを修正して、dlfn.c のなかのpragmaを外したらリンクが通った。このpragmaは何を意味するんだろうか。
diff -ur dlcompat-20030629.old/dlfcn.c dlcompat-20030629/dlfcn.c --- dlcompat-20030629.old/dlfcn.c 2008-06-13 10:08:01.000000000 +0900 +++ dlcompat-20030629/dlfcn.c 2008-06-13 10:09:30.000000000 +0900 @@ -157,7 +157,7 @@ static NSSymbol *search_linked_libs(const struct mach_header *mh, const char *symbol); static const char *get_lib_name(const struct mach_header *mh); static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod); -static void dlcompat_init_func(void); +static void dlcompat_init_func(void) __attribute__ ((constructor)); static inline void dolock(void); static inline void dounlock(void); static void dlerrorfree(void *data); @@ -816,7 +816,7 @@ } } -#pragma CALL_ON_LOAD dlcompat_init_func +/* #pragma CALL_ON_LOAD dlcompat_init_func */ static void dlcompat_cleanup(void) {
http://developer.apple.com/qa/qa2005/qa1429.html によれば、CALL_ON_LOADの代わりに constructor attributeを使えと書いてあるのでそうしてある。