Swig C ++ for Java UnsatisfiedLinkError
I am converting C ++ to Java using swig. I am using g ++ to create DLLs and compile.
swig -c++ -java -package preprocessor Point.i
g++ -c -std=c++11 Point.cpp Point_wrap.cxx -I E:\ProgramFiles\jdk\include -I E:\ProgramFiles\jdk\include\win32
g++ -shared Point_wrap.o Point.o -o point.dll
I have no errors compiling and creating dlls. So when I add the generated java files and dlls to my project, I have an UnsatisfiedLinkError when I create a new object. It only appears when I am using Windows 8.1 x86. In the x64 version, everything works fine.
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: preprocessor.PointClassJNI.new_Point__SWIG_0()J
at preprocessor.PointClassJNI.new_Point__SWIG_0(Native Method)
at preprocessor.Point.<init>(Point.java:78)
at GUI.FileWorker.fileParser(FileWorker.java:45)
at GUI.MainWindow$2.actionPerformed(MainWindow.java:139)
This is what swig generates and where the error occurs when creating point = new Point ();
public Point() {
this(PointClassJNI.new_Point__SWIG_0(), true);
}
Someone may have had this problem. I will be very grateful for any help!
+3
source to share
1 answer
Finally I found a solution in this question . Just need to add -Wl, - add-stdcall-alias to my .bat file when I create dll.
swig -c++ -java -package preprocessor Point.i
g++ -c -std=c++11 Point.cpp Point_wrap.cxx -I E:\ProgramFiles\jdk\include -I E:\ProgramFiles\jdk\include\win32
g++ -shared Point_wrap.o Point.o -Wl,--add-stdcall-alias -o point.dll
rkapl, thanks for the answer!
+2
source to share