Solved

JNI unsatisfied link eroor

Posted on 2004-10-12
16
1,016 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
Comment Utility
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
Comment Utility
The following link may shed some light on this:
http://developer.java.sun.com/developer/bugParade/bugs/4225434.html
0
 

Author Comment

by:tigress298
Comment Utility
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
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Please show the java code where you load the library
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 14

Expert Comment

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

Expert Comment

by:Webstorm
Comment Utility
>>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
Comment Utility
I suggest to split the points : sudhakar_koundinya, Webstorm
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
????

Some strange thing happened here
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
:-)
0
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
:-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 56
strDist challenge 35 84
where is session ID cache stored 1 38
unix in java example 9 36
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now