why UndatistiedLinkError in JNI ?

T

tony_lincoln

Dear friends,

I tried to call c++ codes from Java, so I used JNI:
Following the instruction of java JNI official website, I succeeded in
calling HelloWorld.cpp from Java.
However, when I tried to call my C++ calculation which is called
calcBE, there is one error:

E:\>Java Measure
Exception in thread "main" java.lang.UnsatisfiedLinkError: calcBE
at SimilarityMeasure.calcBE (native method)
at SimilarityMeasure.main(SimilarityMeasure.java:42)

I tried to compiled the C++ codes and got different dll files for
several times, but the result is the same: always the error mentioned
above.
In JNI HelloWorld, if there is error, it will be like this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in
java.library.path. So I know that I have to set the path.
But the error I mentioned above has no enough information----I do not
know if I did not compile the C++ codes in a correct way, or if there
are other things wrong.

THank you in advance.
tony
 
G

Gordon Beaton

E:\>Java Measure
Exception in thread "main" java.lang.UnsatisfiedLinkError: calcBE
at SimilarityMeasure.calcBE (native method)
at SimilarityMeasure.main(SimilarityMeasure.java:42)

I tried to compiled the C++ codes and got different dll files for
several times, but the result is the same: always the error mentioned
above.

As you say, it could depend on various things, so more information is
necessary in order to solve the problem.

- what symbols does the dll actually contain? Use a tool like dumpbin,
quickview or depends to see the contents of the compiled dll.
- does your native code use the exact names and signatures generated
by javah?
- do you have a package declaration in your class?
- did you include the header file generated by javah?

/gordon
 
T

TheGist

Dear friends,

I tried to call c++ codes from Java, so I used JNI:
Following the instruction of java JNI official website, I succeeded in
calling HelloWorld.cpp from Java.
However, when I tried to call my C++ calculation which is called
calcBE, there is one error:

E:\>Java Measure
Exception in thread "main" java.lang.UnsatisfiedLinkError: calcBE
at SimilarityMeasure.calcBE (native method)
at SimilarityMeasure.main(SimilarityMeasure.java:42)

I tried to compiled the C++ codes and got different dll files for
several times, but the result is the same: always the error mentioned
above.
In JNI HelloWorld, if there is error, it will be like this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in
java.library.path. So I know that I have to set the path.
But the error I mentioned above has no enough information----I do not
know if I did not compile the C++ codes in a correct way, or if there
are other things wrong.

THank you in advance.
tony


The easy answer may simply be that your dlls are not available. Where
are they? Put them in your current working directory. Does the problem
go away?
 
G

Gordon Beaton

The easy answer may simply be that your dlls are not available.
Where are they? Put them in your current working directory. Does the
problem go away?

According to the error message posted by the OP, the problem is *not*
that the DLL could not be loaded. The problem is that the method
calcBE() could not be found in the DLL.

The solution is to make sure that the correct method names are used in
the native code, and that their names are not mangled in any way by
the C or C++ compiler.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top