Primemaster
Primemaster

Reputation: 312

JNI Unable to load native library

I'm using JNI as mean to connect my java code and C code.

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.

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. I got the jvm.dll in the same folder of the exe and I think JDK PATH is correctly set up. I have no clue for what the problem may be.

I searched for the error but couldn't fix it.

Upvotes: 0

Views: 5670

Answers (1)

samgak
samgak

Reputation: 24417

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. 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.

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). This means that the additional dependencies will be statically linked into your .dll, instead of needing to be located at runtime.

Upvotes: 2

Related Questions