简体   繁体   中英

Java JNI: Specify path to dependent shared library

I built a JNI library libmyjni.dylib and it is linked with libthirdparty.dylib . While starting my Java application, I set -Djava.library.path=/path/to/native/libs but that path is not being used to load libthirdparty.dylib . Java is always looking for libthirdparty.dylib under <project_root>/lib folder. What parameter do I set so as to look for libthirdparty.dylib in the same path as java.library.path ?

This is the error I get if I don't put libthirdparty.dylib under <project_root>/lib . I also tried creating /etc/ld.so.conf with path to libthirdparty.dylib in int but that did not help as well.

java.lang.UnsatisfiedLinkError: <java_library_path>/libmyjni.dylib: dlopen(<java_library_path>/libmyjni.dylib, 1): Library not loaded: lib/libthirdparty.dylib
  Referenced from: <java_library_path>/libmyjni.dylib
  Reason: image not found

java.library.path is for JNI libraries only, not libraries they depend on. The system path is used for those, which is system-dependent: set PATH , LD_LIBRARY_PATH , or DYLD_LIBRARY_PATH (on Windows, Linux, or OSX respectively)

Based on @user207421 and @CHmoonKa comments to the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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