"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Can't My JNI Project Find Dependent Libraries?

Why Can't My JNI Project Find Dependent Libraries?

Posted on 2025-02-26
Browse:307

Why Can't My JNI Project Find Dependent Libraries?

Addressing UnsatisfiedLinkError: Can't Find Dependent Libraries in JNI Projects

When developing Java Native Interface (JNI) projects, you may encounter the error: "java.lang.UnsatisfiedLinkError: C:...path...\mylib.dll: Can't find dependent libraries." This error indicates that the Java Virtual Machine (JVM) cannot locate the shared libraries (DLLs) required by your JNI library.

Addressing the Problem

To resolve the issue, consider the following solutions:

  1. Ensure proper Library Path: Verify that the dependent libraries (e.g., libsndfile-1.dll) are in the same directory as the main library (mylib.dll) or in a directory listed in the Windows PATH environment variable. The JVM relies on this library path to locate the required dependencies.
  2. Fix Method Name Mangling: Double-check that the method names in the JNI library match exactly with those in the corresponding JNI header file. Visual Studio compilers may mangle method names, so ensure you specify the appropriate linker flags to generate consistent naming.
  3. Specify Library Path Explicitly: If the previous methods fail, you can explicitly set the java.library.path system property to the directory containing the dependent libraries. This overrides the default library search path.

In Visual Studio 2010 on macOS, the target platform should be set to Windows, as you are testing on Windows XP. If development is done on Windows, set the target platform accordingly.

Additional Tips

For further reference, consult "The JNI Book" or the Oracle HTML version of the JNI Specification. You can also use the command "java -XshowSettings:properties -version" to identify the shared library search path.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3