[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1079
  • Last Modified:

JNI unsatisfied link eroor

I am writing using JNI to translate web based queries generated in Java classes to C based queries over a socket connection.  Right now all the classes are in the same directory as much of the other C code.  At first, I had an unsatisfied link error due to not setting the proper java library path, but I fixed that.  I am still getting an unsatified link error, but this time in java's main method when invoking the native "submitQuery" method.  I haven't been able to figure out how to resolve this one.  Any assistance would be much appreciated.  This is being compiled and run on a Solaris machine.
0
tigress298
Asked:
tigress298
  • 5
  • 4
  • 2
  • +1
2 Solutions
 
sudhakar_koundinyaCommented:
The cause is your c++/c dll is not binded correctly with Java API
0
 
sudhakar_koundinyaCommented:
The following link may shed some light on this:
http://developer.java.sun.com/developer/bugParade/bugs/4225434.html
0
 
tigress298Author Commented:
I am getting the following output when running the -verbose:jni command:

sfoste03@sunlp0001-(74): java -verbose:jni JNIQuery
[Loaded native library: /usr/java1.2/jre/lib/sparc/libjava.so]
[Loaded native library: /usr/java1.2/jre/lib/sparc/libzip.so]
[Dynamic-linking native method java/lang/Object.registerNatives ...]
[Dynamic-linking native method java/lang/Class.registerNatives ...]
[Dynamic-linking native method java/lang/Thread.registerNatives ...]
[Dynamic-linking native method java/lang/System.registerNatives ...]
[Dynamic-linking native method java/lang/Class.getPrimitiveClass ...]
[Dynamic-linking native method java/security/AccessController.getStackAccessControlContext ...]
[Dynamic-linking native method java/lang/System.initProperties ...]
[Dynamic-linking native method java/io/FileInputStream.initIDs ...]
[Dynamic-linking native method java/io/FileDescriptor.initIDs ...]
[Dynamic-linking native method java/io/FileOutputStream.initIDs ...]
[Dynamic-linking native method java/lang/System.setIn0 ...]
[Dynamic-linking native method java/lang/ClassLoader.getCallerClassLoader ...]
[Dynamic-linking native method java/lang/Class.forName0 ...]
[Dynamic-linking native method java/security/AccessController.doPrivileged ...]
[Dynamic-linking native method java/lang/System.setOut0 ...]
[Dynamic-linking native method java/lang/System.setErr0 ...]
[Dynamic-linking native method java/lang/Compiler.registerNatives ...]
[Dynamic-linking native method java/io/FileSystem.getFileSystem ...]
[Dynamic-linking native method java/io/UnixFileSystem.initIDs ...]
[Dynamic-linking native method java/security/AccessController.doPrivileged ...]
[Dynamic-linking native method java/io/UnixFileSystem.list ...]
[Dynamic-linking native method java/io/UnixFileSystem.canonicalize ...]
[Dynamic-linking native method java/io/UnixFileSystem.getBooleanAttributes0 ...]
[Dynamic-linking native method java/lang/ClassLoader.findLoadedClass ...]
[Dynamic-linking native method java/lang/ClassLoader.findBootstrapClass ...]
[Dynamic-linking native method java/security/AccessController.doPrivileged ...]
[Dynamic-linking native method java/lang/String.intern ...]
[Dynamic-linking native method java/lang/System.getCallerClass ...]
[Loaded native library: /usr/java1.2/jre/lib/sparc/libzip.so]
[Dynamic-linking native method java/util/zip/ZipFile.initIDs ...]
[Dynamic-linking native method java/util/zip/ZipFile.open ...]
[Dynamic-linking native method java/util/zip/ZipFile.getTotal ...]
[Dynamic-linking native method java/util/zip/ZipFile.getEntry ...]
[Dynamic-linking native method java/util/zip/ZipEntry.initIDs ...]
[Dynamic-linking native method java/util/zip/ZipEntry.initFields ...]
[Dynamic-linking native method java/util/zip/ZipFile.getCSize ...]
[Dynamic-linking native method java/util/zip/ZipFile.getMethod ...]
[Dynamic-linking native method java/util/zip/Inflater.initIDs ...]
[Dynamic-linking native method java/util/zip/Inflater.init ...]
[Dynamic-linking native method java/util/zip/Inflater.inflateBytes ...]
[Dynamic-linking native method java/util/zip/ZipFile.read ...]
[Dynamic-linking native method java/lang/Throwable.fillInStackTrace ...]
[Dynamic-linking native method java/io/FileInputStream.open ...]
[Dynamic-linking native method java/io/UnixFileSystem.getLength ...]
[Dynamic-linking native method java/io/FileInputStream.readBytes ...]
[Dynamic-linking native method java/lang/ClassLoader.defineClass0 ...]
[Unable to load native library: /data0/Baselines/sfoster/CPNet/bin/libNewServerClient.so]
ld.so.1: /usr/java1.2/bin/../jre/bin/../bin/sparc/native_threads/java: fatal: relocation error: file /data0/Baselines/sfoster/CPNet/bin/libNewServerClient.so: symbol locs: referenced symbol not found
Exception in thread "main" [Dynamic-linking native method java/lang/Object.getClass ...]
[Dynamic-linking native method java/io/FileOutputStream.writeBytes ...]
java.lang.UnsatisfiedLinkError: no NewServerClient in java.library.path
[Dynamic-linking native method java/lang/Throwable.printStackTrace0 ...]
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.<init>(Throwable.java:94)
        at java.lang.Error.<init>(Error.java:50)
        at java.lang.LinkageError.<init>(LinkageError.java:43)
        at java.lang.UnsatisfiedLinkError.<init>(UnsatisfiedLinkError.java:42)
        at java.lang.ClassLoader.loadLibrary(Compiled Code)
        at java.lang.Runtime.loadLibrary0(Runtime.java:473)
        at java.lang.System.loadLibrary(System.java:778)
        at <Unloaded Method>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
WebstormCommented:
Hi tigress298,

>> [Unable to load native library: /data0/Baselines/sfoster/CPNet/bin/libNewServerClient.so]
>> ld.so.1: /usr/java1.2/bin/../jre/bin/../bin/sparc/native_threads/java: fatal: relocation error: file /data0/Baselines/sfoster/CPNet/bin/libNewServerClient.so: symbol locs: referenced symbol not found

>> The cause is your c++/c dll is not binded correctly with Java API
right. you have to use javah on the compiled class. this tool generate a C header file you must use to make your C library.
0
 
tigress298Author Commented:
I did that.  Below are my steps of creation.

javac JNIQuery.java
javah -jni -o JNIQuery.h JNIQuery
made my NewServerClient.c class with #include "JNIQuery.h"
cc -G -o NewServerClient.so NewServerClient.c
java -verbose:jni JNIQuery
0
 
CEHJCommented:
Please show the java code where you load the library
0
 
sudhakar_koundinyaCommented:
I want to see your c/c++ code. I suspect memory allocation problems in ur code
0
 
WebstormCommented:
>>cc -G -o NewServerClient.so NewServerClient.c
You should have in the static statement of your class :
    static{
        System.loadLibrary("NewServerClient"); // no extension
    }


>>ld.so.1: /usr/java1.2/bin/../jre/bin/../bin/sparc/native_threads/java: fatal: relocation error: >>file /data0/Baselines/sfoster/CPNet/bin/libNewServerClient.so: symbol locs: referenced symbol not found

The symbol named "locs" can't be found. You probably forgot to link your library with the one defining this symbol.
0
 
WebstormCommented:
I suggest to split the points : sudhakar_koundinya, Webstorm
0
 
sudhakar_koundinyaCommented:
????

Some strange thing happened here
0
 
sudhakar_koundinyaCommented:
:-)
0
 
WebstormCommented:
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now