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:
-
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.
-
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.
-
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.
The above is the detailed content of Why Can't My JNI Project Find Dependent Libraries?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn