Finding .so from jna.library.path

1,388 views
Skip to first unread message

Hlöðver Sigurðsson

unread,
Nov 17, 2018, 9:10:12 PM11/17/18
to Java Native Access
I'm totally confused, I'm loading 3 seperate jna based java apps that require .so files from 3 different locations, I have a colon seperated list of folders that I know all of the .so files are located at.

Depending on how the jna.library.path is set, I can import each individually, but at no point all of them. Consider this


Here's a debug info from `-Djna.debug_load=true`

notice how it's not finding libcsound64.so despite its directory `/run/current-system/sw/lib` is listed (this strange location is due to NixOs distro of linux)

```
Looking for library 'csound64'
Adding paths from jna.library.path: native/linux/x86_64:native/linux/x86_64:/run/current-system/sw/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/home/hlolli/.nix-profile/lib:/run/current-system/sw/lib:
Trying /run/current-system/sw/lib/libcsound64.so
Adding system paths: []
Trying /run/current-system/sw/lib/libcsound64.so
Looking for version variants
Trying /run/current-system/sw/lib/libcsound64.so.6.0
Looking in classpath from sun.misc.Launcher$AppClassLoader@135fbaa4 for csound64
```


then cosider this, when I don't load other libraries and don't append their directories

```
Looking for library 'csound64'
Adding paths from jna.library.path: /run/current-system/sw/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/home/hlolli/.nix-profile/lib:/run/current-system/sw/lib:
Trying /run/current-system/sw/lib/libcsound64.so
Found library 'csound64' at /run/current-system/sw/lib/libcsound64.so
```

then it's found right away. This debug info doesn't make much sense to me, the java library is in a jar so everything is the same, besides the jna lib path, which is different.

Hlöðver Sigurðsson

unread,
Nov 17, 2018, 9:22:12 PM11/17/18
to jna-...@googlegroups.com
Some information missing, I'm running on jna 5.1.0 Java 1.8.0_181 and the full error message is


Adding paths from jna.library.path: native/linux/x86_64:native/linux/x86_64:/run/current-system/sw/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/home/hlolli/.nix-profile/lib:/run/current-system/sw/lib:
Trying /run/current-system/sw/lib/libcsound64.so
Adding system paths: []
Trying /run/current-system/sw/lib/libcsound64.so
Looking for version variants
Trying /run/current-system/sw/lib/libcsound64.so.6.0
Looking in classpath from sun.misc.Launcher$AppClassLoader@135fbaa4 for csound64
UnsatisfiedLinkError Unable to load library 'csound64': Native library (linux-x86-64/libcsound64.so) not found in resource path (... classpath ...)

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthias Bläsing

unread,
Nov 18, 2018, 4:52:27 PM11/18/18
to jna-...@googlegroups.com
Hi Hlöðver,

yeah, error reporting when loading of native library fails is not
always helpful. Could you please have a look at:

https://github.com/java-native-access/jna/pull/1038

that PR includes the native error messages into the final exception
message and also includes all exceptions that are throw when loading
fails into the final exception (only on Java >= 7).

I pushed snapshot builds here:

https://oss.sonatype.org/content/repositories/snapshots/net/java/dev/jna/jna/5.1.1-SNAPSHOT/jna-5.1.1-20181118.214402-1.jar

It would be great if you could check to see if the added information
already solves your problem. If not. I'd be interested in the exception
message and the backtrace(s) of the call.

Greetings

Matthias

Caleb Hulbert

unread,
Dec 3, 2018, 4:16:00 PM12/3/18
to Java Native Access
Hi Hlöðver, 

I'm not sure this is the same cause as you, but I was having similar error reporting, where it would claim to look in the exact place it existed, and still not find the shared objects. 
I used the snapshot Matthias linked to (thank you for that!) and received better error reporting, which showed that it was actually finding the shared object I was pointing it to, but that in turn also was pointing to a shared object, which it could not find.

In my situation, the solution was to add the dependency path to the LD_LIBRAY_PATH as well, and in turn add that to the jna.library.path. I was able to successfully link after doing this! Hope this helps!

Hlöðver Sigurðsson

unread,
Dec 3, 2018, 4:24:28 PM12/3/18
to jna-...@googlegroups.com
Thanks for replying, I lost this thread (most likely due to stress that day), I was able to make ugly hack to make it work. I have a suspicion that the sequence of which library is loaded matters. Because I'm loading .so files for supercollider and csound, both of which share 3rd party dependencies like libsndfile and libjack2. I will try the snapshot and report!

Hlöðver Sigurðsson

unread,
Feb 10, 2019, 4:56:22 PM2/10/19
to jna-...@googlegroups.com
Excuse my 2 month dormancy. I tested the 5.2.0 release, and I notice better error messages. So the .so is found but it's not finding nested .so dependencies.

CompilerException java.lang.UnsatisfiedLinkError: Unable to load library 'csound64':
native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
Native library (linux-x86-64/libcsound64.so) not found in resource path

so libcsound64.so needs libsndfile.so.1.0 but java jna can't find it. Doing readelf, it shows clearly that libsndfile is in the runpath

$ readelf -d /run/current-system/sw/lib/libcsound64.so

Dynamic section at offset 0x302160 contains 36 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libsndfile.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libcurl.so.4]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libmvec.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libcsound64.so.6.0]
 0x000000000000001d (RUNPATH)            Library runpath: [/nix/store/6pr06lwr0fl6jl5nzmgqjif6h503ivpb-libsndfile-1.0.28/lib:/nix/store/k4x61wg9lyjynxxyh44f9994l7dxvma4-curl-7.61.1/lib:/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib]

This is maybe a distro "issue", since I'm using NixOs. But I'm bit surprised that jna is trying to load the library but not the operating system's library loader. Maybe this is just an issue of reading the runpath?

The first element in the runpath containes the libsndfile.so.1.0 which libcsound64.so needs

$ ls /nix/store/6pr06lwr0fl6jl5nzmgqjif6h503ivpb-libsndfile-1.0.28/lib/          
libsndfile.la  libsndfile.so  libsndfile.so.1  libsndfile.so.1.0.28

For completion, I'll post the debug information

Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Looking for library 'jack64'
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Adding paths from jna.library.path: native/linux/x86_64
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Trying libjack64.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: libjack64.so: cannot open shared object file: No such file or directory
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Adding system paths: []
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Trying libjack64.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: libjack64.so: cannot open shared object file: No such file or directory
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Looking for version variants
Feb 10, 2019 10:50:35 PM com.sun.jna.Native extractFromResourcePath
INFO: Looking in classpath from sun.misc.Launcher$AppClassLoader@135fbaa4 for jack64
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: Native library (linux-x86-64/libjack64.so) not found in resource path (..elided...)
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Looking for library 'jack'
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Adding paths from jna.library.path: native/linux/x86_64
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Trying libjack.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Found library 'jack' at libjack.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Looking for library 'csound64'
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Adding paths from jna.library.path: native/linux/x86_64
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Trying libcsound64.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Adding system paths: []
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Trying libcsound64.so
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Looking for version variants
Feb 10, 2019 10:50:35 PM com.sun.jna.Native extractFromResourcePath
INFO: Looking in classpath from sun.misc.Launcher$AppClassLoader@135fbaa4 for csound64
Feb 10, 2019 10:50:35 PM com.sun.jna.NativeLibrary loadLibrary
INFO: Loading failed with message: Native library (linux-x86-64/libcsound64.so) not found in resource path (..elided...)
CompilerException java.lang.UnsatisfiedLinkError: Unable to load library 'csound64':
native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
native/linux/x86_64/libsndfile.so.1: version `libsndfile.so.1.0' not found (required by /run/current-system/sw/lib/libcsound64.so)
Native library (linux-x86-64/libcsound64.so) not found in resource path (...elided...), compiling:(panaeolus/csound/csound_jna.clj:14:1) 

Hlöðver Sigurðsson

unread,
Feb 16, 2019, 10:46:54 AM2/16/19
to jna-...@googlegroups.com
Ok so I'm starting to understand this better,

the problem is that I'm importing two different libraries that both depend on different versions of the library libsndfile.

My workaround hack works because I one library (libscsynth) can use the libsndfile from libcsound64 but not vice versa.

Maybe this is just a fact of java that one can't load the same library twice?

Hlöðver Sigurðsson

unread,
Feb 16, 2019, 11:28:28 AM2/16/19
to jna-...@googlegroups.com
Sorry for the "spam".

So I forked the jna project and compiled it, I was going to LOG some places and try to see if I could hack something. But amazingly the 5.2.1-SNAPSHOT (latest git) doesn't produce these errors.

Not sure if my complaints had anything to do with it, but all the best to the maintainers of JNA, thanks!
Reply all
Reply to author
Forward
0 new messages