简体   繁体   中英

Cannot Open Shared Object file - C++ library in Java

I am trying to use a C++ compiled library in my Java code. I set java.library.path to /usr/local/lib/ and I have all the .so files for the libraries installed there.

However, when I try to run the Java application I see the following:

Native code library failed to load. 
java.lang.UnsatisfiedLinkError: /usr/local/lib/libA.so: libB.so.2.4: cannot open shared object file: No such file or directory

However the file seems to be there:

ls /usr/local/lib/libB.so.2.4
lrwxrwxrwx 1 root root 20 Jan 24 16:33 /usr/local/lib/libB.so.2.4 -> libB.so.2.4.5

The symlinked file also exists. Any idea why this library can't be found?

Java was able to load the native code for library A ( libA.so ) and when it ran that native code there was a dependency on libB.so (however, it's in native code at that point - outside of the JVMs control). At that point, you must use the native libraries on the system. The usual mechanism is to set the LD_LIBRARY_PATH environment variable or use ldconfig (per the man page) which says in part

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so.

If you are using WebLogic: make sure you have a system variable called USTART_LD_LIB in the wlstart -script of weblogic that overwrites LD_LIBRARY_PATH variable. So you need to set this variable also append the lib to this variable and also simultaneously set LD_LIBRARY_PATH .

The reason is you cannot keep on exporting the variables before start of your app manually..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM