我正在尝试使用java的本地库。vendor为我提供了适当的java文件(可以在“最新的JNI实现”下找到here )。
此外,我已经设置了-Djava.library.path="D:\*absolutePathToDLLFolder*",并且我也尝试了相对路径,结果相同。
现在,当运行我的小应用程序时,我得到了以下错误:
java.lang.UnsatisfiedLinkError: com.neurosky.thinkgear.ThinkGear.GetDriverVersion()I
at com.neurosky.thinkgear.ThinkGear.GetDriverVersion(Native Method)
at eu.expandable.mindwave.Start.main(Start.java:23)下面是我的主类:
package eu.expandable.mindwave;
import com.neurosky.thinkgear.ThinkGear;
/**
*
* @author Andre
*/
public class Start {
public static void main(String[] args){
System.out.println("Mindwave Test");
//testing if os is 32bit
//otherwise it wont work (under windows)
int arc = Integer.valueOf(System.getProperty("sun.arch.data.model"));
if(arc != 32) {
System.err.println("Sorry, only 32bit platforms are supported");
System.exit(0);
}
try {
System.out.println("Mindwave Driver version: " + ThinkGear.GetDriverVersion());
}catch(UnsatisfiedLinkError e){
System.err.println("Are you sure the library is existing?");
System.out.println("Will exit now");
e.printStackTrace();
System.exit(-1);
}
System.out.println("Trying to build a connection...");
int connID = ThinkGear.GetNewConnectionId();
System.out.println("Done. Connection ID is: " + connID);
System.out.println("Release connection");
ThinkGear.FreeConnection(connID);
System.out.println("Connection is freed");
System.out.println("Exit");
}
}我会认为我的代码是正确的,但由于某些原因,它仍然崩溃。我在Windows 7 64位和Java 8(32位)下运行。
发布于 2014-04-29 13:39:40
下面是一个PD过程,它可能会帮助您识别问题。我看到你已经检查了32和64,但我把这个检查留在了这个过程中,因为它可能会在以后对其他人有所帮助。
将以下内容添加到您的程序中,以确定两个运行时环境之间的arch和load路径的差异。调查path/arch中的任何差异。
System.out.println(System.getProperty("java.library.path"));
System.out.println(System.getProperty("sun.arch.data.model"));您可以使用dumpbin.exe实用工具来标识正在加载的DLL所需的依赖项。确保依赖项存在。示例用法:
C:> dumpbin /imports your.dll
Dump of file your.dll
File Type: DLL
Section contains the following imports:
**KERNEL32.dll**您可以使用where.exe命令查找依赖项的位置。示例用法:
C:>where KERNEL32.dll
C:\Windows\System32\kernel32.dll如果您看到:
C:>where KERNEL32.dll
INFO: Could not find files for the given pattern(s)调查依赖DLL不在路径上的原因。
您可以使用dumpbin.exe命令来检查64位与32位。
示例:
C:>dumpbin /headers yourd.dll
Dump of file yourd.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86) <-- 32bit DLL
C:>dumpbin /headers yourd.dll
Dump of file yourd.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64) <-- 64bit DLL调查main/dependent之间的所有32位与64位不匹配。如果您的JVM是32位的,则需要使用32位的DLL。如果您的JVM是64位的,则需要使用64位的DLL。(可以在64位操作系统上运行32位JVM,但JNI DLL必须是32位的(DLL匹配的是JVM,而不是操作系统)。
发布于 2014-04-29 13:44:40
com.neurosky.thinkgear.ThinkGear.GetDriverVersion()I:
java.lang.UnsatisfiedLinkError
这意味着找到了该库,JVM现在正在尝试查找其中的本机方法。这里的问题是,上面给出了本机签名的方法实际上并没有在库中找到。您必须发布该库的.h和.c文件,至少是相关的方法头文件,才能获得进一步的帮助。但你应该跑
javah com.neurosky.thinkgear.ThinkGear并将新生成的.h文件与该项目中的当前文件及其.c文件进行比较。
https://stackoverflow.com/questions/23014928
复制相似问题