简体   繁体   English

JNI 无法加载本机库

[英]JNI Unable to load native library

I'm using JNI as mean to connect my java code and C code.我使用 JNI 作为连接我的 java 代码和 C 代码的意思。

The code compiles fine and the screen GUI application opens and then closes which means that there is nothing wrong with that part of the code which is pure C.代码编译良好,屏幕 GUI 应用程序打开然后关闭,这意味着纯 C 的那部分代码没有任何问题。

However when I run the program the output console immediately tells me:但是,当我运行程序时,输出控制台立即告诉我:

Error occurred during initialization of VM
Unable to load native library: Can't find dependent libraries

and returns 1 as error code.并返回1作为错误代码。 I got the jvm.dll in the same folder of the exe and I think JDK PATH is correctly set up.我在 exe 的同一文件夹中得到了 jvm.dll,我认为 JDK PATH 设置正确。 I have no clue for what the problem may be.我不知道问题可能是什么。

I searched for the error but couldn't fix it.我搜索了错误,但无法修复。

That error means that the Java VM is finding and attempting to load your .dll, but additional .dlls that your .dll depends on cannot be found.该错误意味着 Java VM 正在查找并尝试加载您的 .dll,但找不到您的 .dll 所依赖的其他 .dll。 One option is to make sure that those extra dependencies are in the PATH, but that can be tricky because it depends on setting up environment variables during installation, setting them at runtime, or placing additional .dlls into the same folder.一种选择是确保那些额外的依赖项在 PATH 中,但这可能很棘手,因为这取决于在安装期间设置环境变量、在运行时设置它们,或将其他 .dll 放入同一文件夹中。

Another way to fix it is to use the -static linker flag when linking your .dll (note that this is not mutually exclusive with the -shared option, which tells the linker to package your code into a .dll).修复它的另一种方法是在链接 .dll 时使用-static链接器标志(请注意,这与-shared选项并不互斥,它告诉链接器将您的代码打包到 .dll 中)。 This means that the additional dependencies will be statically linked into your .dll, instead of needing to be located at runtime.这意味着附加依赖项将静态链接到您的 .dll 中,而不需要在运行时定位。

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

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