« Welcome to being searched on the subway | Main | And on the other side... »
July 22, 2005
Curse you JNI
When you callSystem.loadLibrary("foo") Java tries to load
libfoo.so. That's actually sensible behavior, but
unfortunately the error message doesn't tell you what file
it's trying to load. It just says:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no foo in java.library.pathWhich doesn't actually help that much if you've forgotten to put "lib" in front of your file name.
Posted by ekr at July 22, 2005 6:33 PM | Filed under:
Comments
Welcome to non-Windows. It gets even worse when you start dealing with libfoo.so.2 and libfoo.so.2.0.0.
As far as DLL hell goes, non-Windows has got nuthin' on Windows. One thing is better that I'll grant -- having multiple revisions of the same library is at least possible in a non-hackish way (that is, if your code needs libfoo.so.1 and some other code needs libfoo.so.2 you can put them in the same directory and things work as you expect).
So as much as I don't like it, I do see some of the reasons. It does take getting used to. The JNI just ends up passing the library name to dlopen(3) on non-Windows, so it doesn't even realize that it's getting mangled at the lowest level.
On OS X it's even worse -- they use .dylib for their dynamic libraries EXCEPT when they're JNI extensions, where they use .jnilib for the file extension. Sigh.
One small thing to be happy about with this scheme in Java -- the parameter to loadLibrary doesn't have to change for every platform. It gets mangled into the appropriate platform filename.
Posted by: Blake at July 23, 2005 7:37 PM