Java JNI linking multiple libraries

2019-09-04 01:30发布

问题:

I have written some code to load the shared object in Java. Here's the sample code:

public class helloworld
{
        static
        {
               System.loadLibrary("calcJava");
        }
        public static void main(String [] args)
        {
                System.out.println("Hello");
        }
}

Shared object "calcJava" is further dependent on another shared object. libMath.so

When I attempt to run this, it always gives me unsatisfiedlinkerror with undefined symbol error from dependent .so (libMath.so).

Before executing the java program, here's what I am doing:

1) Set LD_LIBRARY_PATH to both the .so

2) Set CLASSPATH to the jar file

3) Run the java program with "java helloworld -Djava.library.path=/path/to/shared/object1:/path/to/shared/object2

Can anyone please explain why am I getting UnsatisfiedLinkError?

Here's the stacktrace

Exception in thread "main" java.lang.UnsatisfiedLinkError: /path/to/libcalcJava.so: /path/to/libcalcJava.so: undefined symbol: _xxx_xxx_Xxx_xx at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at helloworld.(helloworld.java:6)

Thanks