3

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.

Sahithi V
  • 31
  • 1
  • 4

2 Answers2

1

That library depends on some other shared library that isn't present, which contains the missing entry point.

Review the installation instructions.

user207421
  • 305,947
  • 44
  • 307
  • 483
-3

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.

Chetan Verma
  • 735
  • 5
  • 10
  • 1
    Please set you path correctly so when you load library the should come like this- /home/tomcat/sahithi/ExprParser/lib/InfExprParser.so right now it is coming like this- /home/tomcat/sahithi/ExprParser/libInfExprParser.so which is wrong. – Chetan Verma Jun 14 '15 at 08:59
  • You have zero information as to which is the correct path for the .so. All we know is that `loadLibrary()` found it in the place indicated. The `lib` is automatically prepended by `loadLibrary()`, as it clearly states in the Javadoc. It is clearly not wrong, otherwise why would it be loaded at all? You also have zero information about who upvoted or downvoted this answer. It's a secret ballot. – user207421 Jun 14 '15 at 09:58
  • thanks! can you explain the difference between load and loadLibrary() generated paths then as they both do the same work in a way. – Chetan Verma Jun 14 '15 at 10:35
  • I suggest that you read the Javadoc. I don't see why I should be expected to repeat it all here, or why you're answering questions about things you haven't studied properly. – user207421 Jun 14 '15 at 10:55