Solved

JNI unsatisfied link eroor

Posted on 2004-10-12
16
1,032 Views
Last Modified: 2012-05-05
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
Comment
Question by:tigress298
  • 5
  • 4
  • 2
  • +1
16 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12287687
The cause is your c++/c dll is not binded correctly with Java API
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 250 total points
ID: 12287698
The following link may shed some light on this:
http://developer.java.sun.com/developer/bugParade/bugs/4225434.html
0
 

Author Comment

by:tigress298
ID: 12287774
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
Industry Leaders: 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!

 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 250 total points
ID: 12288064
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
 

Author Comment

by:tigress298
ID: 12288234
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12290125
Please show the java code where you load the library
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12290213
I want to see your c/c++ code. I suspect memory allocation problems in ur code
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 12296011
>>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
 
LVL 13

Expert Comment

by:Webstorm
ID: 12555221
I suggest to split the points : sudhakar_koundinya, Webstorm
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12584299
????

Some strange thing happened here
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12679509
:-)
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 12680445
:-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 84
web application structure 18 111
Adding multiple JVM environments to RedHat 6 7 69
Java: anonymous class 4 37
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question