Note that there are some explanatory texts on larger screens.

plurals
  1. POSystem.loadLibrary does not work. UnsatisfiedLinkError for the second lib in chain
    primarykey
    data
    text
    <p>I have java program Client.class that uses cpp shared library libclient.so via JNI. libclient.so is built as shared and uses cpp shared library libhttp.so.</p> <p>libclient.so and libhttp.so are placed in folder <code>/home/client/lib64</code> <br>Client.class is placed in <code>/home/client/bin</code></p> <p>Client can load library with</p> <ol> <li>System.load and environment variable LD_LIBRARY_PATH</li> <li>System.loadLibrary and -Djava.library.path</li> </ol> <p>The first way works fine.</p> <p><code>export LD_LIBRARY_PATH = /home/client/lib64</code> <br></p> <p>java -classpath ./bin Client</p> <p>The secon way fails.</p> <p><code>java -classpath ./bin -Djava.library.path=./../lib64 Client</code> <br></p> <pre><code>java.lang.UnsatisfiedLinkError: /home/client/lib64/libclient.so: libhttp.so: cannot open shared object file: No such file or directory </code></pre> <p>When I put libhttp.so into /usr/lib64 the second way works fine.</p> <p><strong>Why libclient.so is looking for libhttp.so in /usr/lib64 if I use System.loadLibrary? How can I fix it without coping libhttp.so into /usr/lib64?</strong></p> <p><em>My loading code:</em></p> <pre><code> //Try load from -Djava.library.path boolean found = false; String lib = "client"; try { System.loadLibrary(lib); found = true; } catch (UnsatisfiedLinkError e) { e.printStackTrace(); } //Try load from LD_LIBRARY_PATH if (!found) { lib = "libclient.so"; String ld_lib_path = System.getenv("LD_LIBRARY_PATH"); String[] paths = ld_lib_path.split(":"); for(int i=0; i&lt;paths.length; i++) { String p = paths[i]; File x = new File(p, lib); if (x.exists()) { System.load(x.getAbsolutePath()); found = true; break; } } } </code></pre> <p>Additional information.</p> <p>If I test libclient.so with ldd then I see: libhttp.so => not found If I set export LD_LIBRARY_PATH = /home/client/lib64 then I see: libhttp.so => /home/client/lib64/libhttp.so</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload