I want to call some function of liba.so from other libb.so. libb.so is dynamic so library that implement native method which i have loaded using System.loadLibrary("b") inside JNI. first i have set complete path for both of .so inside jni using java.library.path but when i run my java programs , while loading shared library libb.so, it gives below error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: x/y/z/libb.so: liba.so: cannot open shared object file: No such file or directory.
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
first i have linked shared library liba.so with other shared library libb.so during compilation using
g++ -shared -o libb.so -fPIC b.cc -L/x/y/z -la
(say complete path of liba.so is /x/y/z)
In JNI, i have set java.library.path pragmatically that contains complete path of liba.so, libb.so and then i used to load JNI native library libb.so as
(say complete path of libb.so is a/b/c and complete path of liba.so is x/y/z.)
String libpath = "x/y/z" + "a/b/c";
System.setProperty( "java.library.path", libpath);
try {
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
}
catch (Exception e)
{
System.out.println(e);
}
// here i am able to print/fetch correct java.library.path. (path of both shared library saved correctly into java.library.path)
static {
System.loadLibrary("b");
}
when my java programs load this dynamic library of static block , it gives below error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: x/y/z/liba.so: libb.so: cannot open shared object file: No such file or directory.
Note: When i set path of liba.so in LD_LIBRARY_PATH, this work fine without any error. but i don't want to set LD_LIBRARY_PATH in SHELL. just i want to set java.library.path or LD_LIBRARY_PATH in program itself.
Thanks in Advance!