gluegen question, loading multiple native libs

Didn’t know where else to post this, figured Ken might see it this way since gluegen is related to jogl and joal.

I’m working on some fancy OSGi code which requires native libraries for some heavy lifting. Anyone who has tried complicated JNI will see my problem right away, I need to load multiple native libraries and I can’t alter the PATH or LD_LIBRARY_PATH. -Djava.library.path won’t help either. I know the dependency order, that’s not a problem.

I’ve tried explicitly loading the libraries via System.load/loadLibrary, no dice. I know for a fact the libraries work when I see LD_LIBRARY_PATH, so my problem is convincing the OS to resolve the links between libraries.

I read over this (old) thread: http://forum.java.sun.com/thread.jspa?threadID=768162&messageID=4386566

I’ve dug around in gluegen, jogl, and joal and tried this:


// For example, let's say I've got two libraries libA.so and libB.so
// B depends on A.
// NativeLibrary is from gluegen

// This call works, at least it SAYS that A is loaded. I get a path and resources
// Don't worry about this classloader
NativeLibrary dep = NativeLibrary.open("A", null);
NativeLibrary main = NativeLibrary.open("B", null); // returns null

// If I set LD_LIBRARY_PATH for this example, both libraries will load
// but the function addresses won't resolve

I’d be really nice to figure out how to load dependent native libraries. I guess I could statically compile, but sometimes that can be a royal pain.

I can’t really answer your question, but out of curiosity, why doesn’t -Djava.library.path work for you?

sorry took so long to get back to this, vacation :slight_smile:

There are two reasons java.library.path won’t work. First, OSGi bundles have their own syntax for shipping native libraries based on custom classes loaders so java.library.path is largely circumvented. Second, java.library.path works fine as long as your native library does not depend on additional native libraries (unless the dependent libraries are on the system library path)