[英]Java JNA UnsatisfiedLinkError
I am following this tutorial : http://stuf.ro/calling-c-code-from-java-using-jna . 我正在学习本教程: http : //stuf.ro/calling-c-code-from-java-using-jna 。 The difference is that my class is called main.c not ctest.c.
区别在于,我的类称为main.c而不是ctest.c。 I've created a library inside the project folder as it says there.
我已经在项目文件夹中创建了一个库,正如它在其中所述。 On the next step i created the Java file with this line modified :
在下一步中,我创建了Java文件,并修改了以下行:
CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
to 至
CTest ctest = (CTest) Native.loadLibrary("main", CTest.class);
I have imported jna-4.1.0.jar to my project. 我已经将jna-4.1.0.jar导入到我的项目中。 On run it gives me this error :
在运行它给我这个错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'main': Native library (win32-x86-64/main.dll) not found in resource path ([file:/D:/eclipse/workspace/RXTX/bin/, file:/D:/eclipse/workspace/RXTX/lib/RXTXcomm.jar, file:/C:/Users/Angelo/Downloads/jna-4.1.0.jar])
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at HelloWorld.main(HelloWorld.java:9)
Where do i place my main.c and what do i do with the libctest.so file ? 我应将main.c放在哪里,如何处理libctest.so文件?
If you build a library libctest.so
then you need to load it with CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
如果您构建库
libctest.so
则需要使用CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
加载它CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
(assuming the rest of your setup is correct). (假设其余的设置是正确的)。
Where to place the library is described in the javadoc of the class Native . 库Native的javadoc中描述了库的放置位置。
To get some hints you might print the steps of the JNA library search to the console. 为了获得一些提示,您可以将JNA库搜索的步骤打印到控制台。
System.setProperty("jna.debug_load", "true"));
CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
edit 编辑
How to call the class (amend the classpath and the directory name) 如何调用类(修改类路径和目录名称)
java -classpath jna.jar:. -Djna.library.path=/your/path/to/the/libctest/file HelloWorld
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.