如何在JNI项目中修复UnsatisfiedLinkError(找不到依赖库)(How to fix an UnsatisfiedLinkError (Can't find dependen

编程入门 行业动态 更新时间:2024-10-25 13:23:27
如何在JNI项目中修复UnsatisfiedLinkError(找不到依赖库)(How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project)

我正在使用一个使用JNI的Java项目。 JNI调用自己编写的自定义库,我们来说一下mylib.dll,这取决于第三方库libsndfile-1.dll。

当我运行我的程序,它崩溃了

java.lang.UnsatisfiedLinkError: C:\...path...\mylib.dll: Can't find dependent libraries.

我搜索过这个网站(和其他人),我已经尝试了一些修复:

我跑依赖步行者。 DW给出了一些警告 - libsndfile,MPR.DLL和SHLWAPI.DLL要求的两个库都有“未解析的导入” - 但DW FAQ表示这些警告可以被安全地忽略。

我修改了mylib.dll中的方法名称, 这里建议。 方法名称已经被编译器弄错了,但是我添加了链接器标志,并且dll方法名称现在与我的jni头文件中的那些匹配。

我将所有这些DLL放在同一目录中 - 与调用它们的.jar相同的目录 - 以确保它们在正确的PATH上。

没有骰子。

有人有什么想法吗?

我在MacBook Pro上通过Visual Studio 2010进行开发(通过Parallels)。 我在一台Toshiba笔记本电脑上在Windows XP中进行测试。

I'm working on a Java project that uses the JNI. The JNI calls a custom library that I've written myself, let's say mylib.dll, and that depends on a 3rd party library, libsndfile-1.dll.

When I run my program it crashes with

java.lang.UnsatisfiedLinkError: C:\...path...\mylib.dll: Can't find dependent libraries.

I've searched this site (and others) and I've tried a number of fixes:

I ran dependency walker. DW gave a couple of warnings -- that two libraries required by libsndfile, MPR.DLL and SHLWAPI.DLL, had "unresolved imports" -- but the DW FAQ said that these warnings could be safely ignored.

I fixed the method names in mylib.dll, as suggested here. The method names had somehow gotten mangled by the compiler, but I added linker flags and the dll method names now match those in my jni header file exactly.

I put all of these DLLs in the same directory -- the same directory as the .jar that calls them -- to ensure that they're on the right PATH.

No dice.

Does anyone have any idea what's going on?

I'm doing my development in Visual Studio 2010 on a MacBook pro (via Parallels). I'm doing my testing in Windows XP on a toshiba laptop.

最满意答案

我很确定类路径和共享库搜索路径与彼此无关。 根据JNI Book (这是老版本),在Windows上,如果不使用java.library.path系统属性,则该DLL需要位于当前工作目录或Windows PATH环境变量中列出的目录中。


更新:

看起来Oracle已经从其网站上删除了PDF。 我更新了上面的链接,指出了德克萨斯大学阿灵顿大学生活的PDF实例。

此外,您还可以阅读Oracle的HTML版本的JNI规范 。 它们生活在Java网站的Java 8部分,希望会在一段时间内。


更新2:

至少在Java 8(我没有检查较早的版本)你可以做:

java -XshowSettings:properties -version

找到共享库搜索路径。 在该输出中查找java.library.path属性的值。

I'm pretty sure the classpath and the shared library search path have little to do with each other. According to The JNI Book (which admittedly is old), on Windows if you do not use the java.library.path system property, the DLL needs to be in the current working directory or in a directory listed in the Windows PATH environment variable.


Update:

Looks like Oracle has removed the PDF from its website. I've updated the link above to point to an instance of the PDF living at University of Texas - Arlington.

Also, you can also read Oracle's HTML version of the JNI Specification. That lives in the Java 8 section of the Java website and so hopefully will be around for a while.


Update 2:

At least in Java 8 (I haven't checked earlier versions) you can do:

java -XshowSettings:properties -version

to find the shared library search path. Look for the value of the java.library.path property in that output.

更多推荐

本文发布于:2023-07-22 19:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   项目   如何在   libraries   JNI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!