T
tony_lincoln
Dear Friends,
I am using Visual C++ under Windows 2000 to call c++ from Java. Without
package name, I succeeded; but with package name, I used javah
carefully, but failed. UnsatisfiedLinkError always appears.
The native java code is like this:
*****************
//NatBE.java
package be;
public class NatBE{
private NatBE() {}
public static native double calculateBE (int i1, int i2);
static { System.loadLibrary("TEST4"); }
public static void main (String[] args) {
int i1 = 3;
int i2 = 5;
new NatBE().calculateBE (i1, i2);
}// end main().
}// end class NatBE().
*******************************
I used javac NatBE.java,
a subdir named "be" was created and a NatBE.class created in it.
Then I used
javah -jhi be.NatBE
and be_NatBE.h was created in the same dir as NatBE.java stays. I
called this dir as current dir.
With be_NatBE.h I compiled my C++ codes in Visual C++ 6 and created one
dll file: TEST4.DLL and put it in the current dir.
A subdir named "main" is created in this current dir, and in it, there
is one java code named NatBEMain.java:
*************************************
import be.NatBE;
public class NatBEMain{
public static void main (String[] args) {
int i1 = 3;
int i2 = 5;
System.out.println("result is : " + NatBE.calculateBE (i1, i2);
}
}// end class NatBEMain.
Then I compiled this java code:
Javac NatBEMain.java
There is no mistake, but when I run it,
Java NatBEMain
There is information:
Exception in thread "main" java.lang.UnsatisfiedLinkError: calculateBE
at be.NatBE.calculateBE (Native Method)
at NatBEMain.main (NatBEMain.java:26)
I tried a lot to solve this problem, but failed. I know that I am not
so far from the answer, but can not find the way. Where is wrong with
it? Thanks a lot.
Best wishes.
tony
I am using Visual C++ under Windows 2000 to call c++ from Java. Without
package name, I succeeded; but with package name, I used javah
carefully, but failed. UnsatisfiedLinkError always appears.
The native java code is like this:
*****************
//NatBE.java
package be;
public class NatBE{
private NatBE() {}
public static native double calculateBE (int i1, int i2);
static { System.loadLibrary("TEST4"); }
public static void main (String[] args) {
int i1 = 3;
int i2 = 5;
new NatBE().calculateBE (i1, i2);
}// end main().
}// end class NatBE().
*******************************
I used javac NatBE.java,
a subdir named "be" was created and a NatBE.class created in it.
Then I used
javah -jhi be.NatBE
and be_NatBE.h was created in the same dir as NatBE.java stays. I
called this dir as current dir.
With be_NatBE.h I compiled my C++ codes in Visual C++ 6 and created one
dll file: TEST4.DLL and put it in the current dir.
A subdir named "main" is created in this current dir, and in it, there
is one java code named NatBEMain.java:
*************************************
import be.NatBE;
public class NatBEMain{
public static void main (String[] args) {
int i1 = 3;
int i2 = 5;
System.out.println("result is : " + NatBE.calculateBE (i1, i2);
}
}// end class NatBEMain.
Then I compiled this java code:
Javac NatBEMain.java
There is no mistake, but when I run it,
Java NatBEMain
There is information:
Exception in thread "main" java.lang.UnsatisfiedLinkError: calculateBE
at be.NatBE.calculateBE (Native Method)
at NatBEMain.main (NatBEMain.java:26)
I tried a lot to solve this problem, but failed. I know that I am not
so far from the answer, but can not find the way. Where is wrong with
it? Thanks a lot.
Best wishes.
tony