Monday, April 7, 2014


Global variables are evil, even if they still appear everywhere, often as environment variables. If you use Tibco on Unix, you have to set LD_LIBRARY_PATH to include the native libraries. Among other things, this complicates using a continuous build server that needs different variables for different builds.

If we remove LD_LIBRARY_PATH and set java.library.path instead, we can load native libraries. But if that loaded library then loads another, it naturally looks for it in LD_LIBRARY_PATH and you get something like:

java.lang.UnsatisfiedLinkError: /opt/mds/tibco_8_1/tibrv/8.1/lib/ cannot open shared object file: No such file or directory

that is, the first one is loaded but the second one fails as it has not been loaded via the JVM but directly by Linux (which knows nothing about java.library.path).

Taking a look at the dependencies between the native libs looks like this:

> readelf -a /opt/mds/tibco_8_1/tibrv/8.1/lib/ | grep NEEDED
 0x00000001 (NEEDED)                    Shared library: []
 0x00000001 (NEEDED)                    Shared library: []

So, just needs standard Linux libraries.

> readelf -a /opt/mds/tibco_8_1/tibrv/8.1/lib/ | grep NEEDED
 0x00000001 (NEEDED)                    Shared library: []
 0x00000001 (NEEDED)                    Shared library: []

And in turn, libtibrvcm needs libtibrv and so on.

Using readelf we can then build up the dependency tree (more on the ELF format can be found here).

We can programatically get around this by just setting java.library.path and calling java code like this:


This loads the libraries in order. Changing the order causes a java.lang.UnsatisfiedLinkError.