简体   繁体   English

Java JNA UnsatisfiedLinkError

[英]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 . Nativejavadoc中描述了库的放置位置。

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.

相关问题 JNA-Ubuntu上的java.lang.UnsatisfiedLinkError - JNA - java.lang.UnsatisfiedLinkError on Ubuntu 从Linux上的.jar启动时,Java-JNA和共享库UnsatisfiedLinkError - Java - JNA and shared Libraries, UnsatisfiedLinkError when starting from a .jar on Linux JNA java.lang.UnsatisfiedLinkError和找不到指定的模块 - JNA java.lang.UnsatisfiedLinkError and The specified module could not be found JNA java.lang.UnsatisfiedLinkError:无法加载库&#39;./OUNPPM&#39; - JNA java.lang.UnsatisfiedLinkError: Unable to load library './OUNPPM' JNA UnsatisfiedLinkError异常 - JNA UnsatisfiedLinkError exception JNA在具有正确名称的正确DLL中为Windows API函数抛出java.lang.UnsatisfiedLinkError - JNA throws java.lang.UnsatisfiedLinkError for a Windows API function in the correct DLL with the correct name jna / c#:java.lang.UnsatisfiedLinkError:查找函数“测试”时出错 - jna/c#: java.lang.UnsatisfiedLinkError: Error looking up function 'Test' java.lang.UnsatisfiedLinkError:无法获取com.sun.jna.Pointer类(神经技术Megamatcher SDK) - java.lang.UnsatisfiedLinkError: Can't obtain class com.sun.jna.Pointer (Neurotechnology Megamatcher SDK) JNA UnsatisfiedLinkError - 当我将java.library.path设置为伪值时起作用 - JNA UnsatisfiedLinkError - works when I set java.library.path to a bogus value Applet jna.jar-java.lang.UnsatisfiedLinkError:无法加载库 - Applet jna.jar - java.lang.UnsatisfiedLinkError: Unable to load library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM