I am trying to load a .so file (libInfExprParser.so) using JNI. I do not have the source code for this shared object. I am getting the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:/home/tomcat/sahithi/ExprParser/libInfExprParser.so: /home/tomcat/sahithi/ExprParser/libInfExprParser.so: undefined symbol: _ZN8IUStringC1EPKcm at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(Unknown Source) at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source) at expressionparser.Main.(Main.java:20)
Java code:
native void parseExpr();
static {
System.loadLibrary("InfExprParser");
System.out.println("Loaded expr parser");
}
public static void main(String[] args) {
Main mainObj = new Main().parseExpr();
}
I am using Redhat Linux 64 bit.
Edit:
I ran the following command to get the list of dependent libraries:
[tomcat@zeus ExprParser]$ readelf -d libInfExprParser.so
Dynamic section at offset 0xa048 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x3ed8
0x000000000000000d (FINI) 0x8628
0x0000000000000004 (HASH) 0x158
0x000000006ffffef5 (GNU_HASH) 0x658
0x0000000000000005 (STRTAB) 0x1cc8
0x0000000000000006 (SYMTAB) 0xb40
0x000000000000000a (STRSZ) 4315 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x20a420
0x0000000000000002 (PLTRELSZ) 1776 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x37e8
0x0000000000000007 (RELA) 0x2f90
0x0000000000000008 (RELASZ) 2136 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x2f20
0x000000006fffffff (VERNEEDNUM) 3
0x000000006ffffff0 (VERSYM) 0x2da4
0x000000006ffffff9 (RELACOUNT) 26
0x0000000000000000 (NULL) 0x0
Out of the 6 shared libraries, 5 are present in these locations: /lib and /lib64
libstdc++.so.6 is present in these locations: /usr/lib and /usr/lib64
I don't know which location will be searched for dependent libraries. I tried setting LD_LIBRARY_PATH and executed the jar as follows:
$ export LD_LIBRARY_PATH=/lib64:/usr/lib64
$ java -jar -Djava.library.path=/home/tomcat/sahithi/ExprParser:/lib64:/usr/lib64 ExpressionParser.jar
$ export LD_LIBRARY_PATH=/lib:/usr/lib
$ java -jar -Djava.library.path=/home/tomcat/sahithi/ExprParser:/lib:/usr/lib ExpressionParser.jar
None of this seemed to work. Got the same error as before. Is there anything else that I can try? Thanks.
Please make sure when you are using System.loadLibrary("libname"), then that library must be set on the system path variables
as an alternate you can use System.load("path to lib") here you does not needed to set the lib at path variable, just provide the absolute or relative path to lib.
Please check your case with decried the scenarios above.