Hi All I've found something new. It seems the dlopen() function in Mac is quite normal, but there are some problem inside OpenJDK. I'm calling dlopen("libkrb5.dylib", RTLD_NOW) inside OpenJDK now and it returns NULL. However, if I manually set DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH to /usr/lib, then it works. So I printf the DYLD_FALLBACK_LIBRARY_PATH value, it is changed to something like jre/lib/i386:jre/lib:jre/../lib/i386. According to Apple doc, the default value of it should ~/lib:/usr/lib:/usr/local/lib. If OpenJDK wants to change it to something else, shouldn't it append the new value onto the old one? So I suggest making these changes: --- a/src/solaris/bin/java_md.c +++ b/src/solaris/bin/java_md.c @@ -443,6 +443,9 @@ * variable. */ runpath = getenv(LD_LIBRARY_PATH); +#ifdef __APPLE__ + if (!runpath) runpath = "/usr/local/lib:/usr/lib"; +#endif #endif /* __solaris__ */ #if defined(__linux__) || defined(_ALLBSD_SOURCE) Yes, the default runpath should also include "~/lib", omitted here for brevity. Thanks Max Max (Weijun) Wang wrote:
Hi All
I'm totally new to C programming on Mac.
On other systems I can call dlopen("libkrb5.so", RTLD_NOW) to return a non-NULL pointer to the library. However, on Mac, dlopen("libkrb5.dylib", RTLD_NOW) returns NULL even if I can see the / usr/lib/libkrb5.dylib is right there. What's wrong here?
Also, is there a way to write a cross-platform call? Say, dlopen_smart("krb5")?
I've found the JNI_LIB_NAME() macro. Nice.
Thanks Max