![](/img/trans.png)
[英]UnsatisfiedLinkError Wrapping C++ DLL with SWIG to allow Java developers to use it
[英]Swig C++ to Java UnsatisfiedLinkError
我使用swig將C ++轉換為Java。 我用g ++來創建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 -o point.dll
編譯和創建DLL時我沒有任何錯誤。 因此,當我將生成的java文件和dll放入我的項目時,我在創建新對象時遇到了UnsatisfiedLinkError。 它出現時才使用Windows 8.1 x86。 在x64版本上一切正常。
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)
這是swig生成的,當我創建point = new Point()時會發生錯誤;
public Point() {
this(PointClassJNI.new_Point__SWIG_0(), true);
}
也許有人有這個問題。 我將非常感謝任何幫助!
最后,我在這個問題中找到了解決方案。 當我創建dll時,只需要在我的.bat文件中添加-Wl, - add-stdcall-alias。
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,謝謝回復!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.