JNI question. UnsatisfiedLinkError upon method invocation

C

CliffMacGillivray

I am getting an UnsatisfiedLinkError not when I load the library but
rather when I call a native method whose implementation is inside
the dll.
Some code:
package myPackage;

public class Main{

public static void main(String[] args){
System.load("C:development\\myNative.dll");
someObject j=new someObject();
j.someNativeMethod();
}
}

The exception is thrown not on the load but on the method invocation
j.someNativeMethod();

The someObject class is really basic

public class someObject{

public someObject(){
//nothing here yet
}

public native void someNativeMethod();

public void aJavaMethod(){
someNativeMethod();
}

}

Any advice on what could be causing this? I am sure that the native
method is appropriately defined and all that. I have used a tool
to dump out the symbols form the dll and I am sure everything is there.

Oh, and no, these are not the real class and method names. My employer
is really fanatical about any sort of public code release so I
anonymized the source a little to avoid trouble.
 
P

Pete Barrett

I am getting an UnsatisfiedLinkError not when I load the library but
rather when I call a native method whose implementation is inside
the dll.
....
Any advice on what could be causing this? I am sure that the native
method is appropriately defined and all that. I have used a tool
to dump out the symbols form the dll and I am sure everything is there.
At a guess, the native method in the native DLL requires another DLL
which it can't find.



Pete Barrett
 
G

Gordon Beaton

ok, a quick followup. This works if I don't specify a package!?!?

Then you either didn't specify the _fully_qualified_ classname when
you ran javah, or you didn't use the symbol names in the header file
it generated. They will be different when a package is used.

/gordon
 
C

CliffMacGillivray

Gordon said:
Then you either didn't specify the _fully_qualified_ classname when
you ran javah, or you didn't use the symbol names in the header file
it generated. They will be different when a package is used.

/gordon
D'oh!!
You are right. Also, another respondent was also correct in
that I had another dependent .dll which I needed to load. 2 problems I had.
Thanks for all the help. c.l.j.p rawks! :)
 
R

Roedy Green

System.load("C:development\\myNative.dll");

That code depends on the current directory.

Try System.load("C:\\development\\myNative.dll");

The proper way to do this which will allow other platform
implementations is to do

Try System.loadLibrary("myNative");

and install your library on the java.library.path (see
http://mindprod.com/wassup.html to discover the system property)

For general help with UnsatisfiedLinkError see

http://mindprod.com/jgloss/runerrormessages.html#UNSATISFIEDLINKERROR
 
R

Roedy Green

My employer
is really fanatical about any sort of public code release so I
anonymized the source a little to avoid trouble.

The problem is so often the cause is a tiny spelling or capitalization
error.

You might want to create a SCCSSE. If it works and your real one does
not, you can check for just where the extract differs in form.


Pay special attention to package names.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top