简体   繁体   English

执行使用Eclipse进行JNI调用的Java应用程序失败,并显示UnsatisfiedLinkError:找不到依赖库

[英]Executing Java application that makes a JNI call, with eclipse, fails with UnsatisfiedLinkError: Can't find dependent libraries

I have a Java program that calls a function in a JNI library. 我有一个Java程序,该程序在JNI库中调用一个函数。 The JNI code statically loads another shared library. JNI代码静态加载另一个共享库。

When executing the Java application using Eclipse, I get an error java.lang.UnsatisfiedLinkError: ... Can't find dependent libraries 使用Eclipse执行Java应用程序时,出现错误java.lang.UnsatisfiedLinkError:...找不到依赖库

But, if i execute the same command in commandline, the program works fine. 但是,如果我在命令行中执行相同的命令,则该程序可以正常运行。 What am I doing wrong in Eclipse? 我在Eclipse中做错了什么?

I made sure to go to Debug View -> Processs -> Process Properties to get the same command string and same working directory as Eclipse execution. 我确保转到Debug View-> Processs-> Process Properties,以获取与Eclipse执行相同的命令字符串和相同的工作目录。

Here is a PD procedure that might help you identify the problem. 这是一个PD程序,可以帮助您发现问题。

Add the following to your program to identify the differences in the arch and load paths between the two runtime environments. 将以下内容添加到您的程序中,以识别两个运行时环境之间的架构和加载路径之间的差异。 Investigate any differences in path/arch. 研究路径/拱形中的任何差异。

 System.out.println(System.getProperty("java.library.path"));
 System.out.println(System.getProperty("sun.arch.data.model"));

You can use the dumpbin.exe utility to identify the dependencies needed by the DLL that is being loaded. 您可以使用dumpbin.exe实用工具来识别正在加载的DLL所需的依赖项。 Make sure the dependencies exist. 确保依赖项存在。 Example usage: 用法示例:

C:> dumpbin /imports your.dll 

Dump of file your.dll
File Type: DLL
  Section contains the following imports:
    **KERNEL32.dll**

You can use the where.exe command to find the location of the dependencies. 您可以使用where.exe命令查找依赖项的位置。 Example usage: 用法示例:

C:>where KERNEL32.dll
    C:\Windows\System32\kernel32.dll

If you see: 如果你看到:

C:>where KERNEL32.dll
    INFO: Could not find files for the given pattern(s)

Investigate why the dependent DLL is not on the path. 调查为什么相关的DLL不在路径上。

You can use the dumpbin.exe command to check 64bit vs 32bit. 您可以使用dumpbin.exe命令检查64位和32位。
Example: 例:

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

Investigate any 32bit vs 64bit mismatches between main/dependent. 研究主/从属之间的任何32位与64位不匹配情况。 If your JVM is 32bit, you need to use 32bit DLLs. 如果您的JVM是32位的,则需要使用32位的DLL。 If your JVM is 64bit, you need to use 64bit DLLs. 如果您的JVM是64位的,则需要使用64位的DLL。 ( It is okay to run a 32bit JVM on a 64bit OS but the JNI DLLs must be 32bit ( DLLs match the JVM not the OS ). (可以在64位操作系统上运行32位JVM,但JNI DLL必须为32位(DLL与JVM匹配,而不与OS匹配)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM