环境: ubuntu 16.04, Eclipse Java EE IDE for Web Developers.(Version: Neon.2 Release (4.6.2))
架包 objectdetection_lib.jar 中 ObjectDetectionImplement.class 中有调用 System.loadLibrary
static{
System.loadLibrary("objectdetection");
}
1. 运行时出现以下错误:
/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
sun.arch.data.model = 64
Exception in thread "main" java.lang.UnsatisfiedLinkError: no objectdetection in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at objectdetection.ObjectDetectionImplement.<clinit>(ObjectDetectionImplement.java:35)
at objectdetection_demo.ObjectDetection.main(ObjectDetection.java:23)
此错误需要 将 libobjectdetection.so 所在路径 添加至 java.library.path 环境变量中(即 LD_LIBRARY_PATH);
具体步骤如下:
Run –> Debug Configures –> Enviroment –> new, 在弹出的 New Environment Variable,
Name: LD_LIBRARY_PATH;
Value: /home/robert/Documents/code/objectdetection/build/linux;
2. 出现 System.loadLibrary 库依赖的库无法找到,报错提示的是依赖库的符号找不到,此时需要指定依赖的库路径及库名称;
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/robert/Documents/code/objectdetection/build/linux/libobjectdetection.so: /home/robert/Documents/code/objectdetection/build/linux/libobjectdetection.so: undefined symbol: WebPMemoryWrite
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at objectdetection.ObjectDetectionImplement.<clinit>(ObjectDetectionImplement.java:35)
at objectdetection_demo.ObjectDetection.main(ObjectDetection.java:23)
此错误需要 将 libobjectdetection.so 依赖的 所在路径及库名称 添加至 LD_PRELOAD 环境变量中;
具体步骤如下:
Run –> Debug Configures –> Enviroment –> new, 在弹出的 New Environment Variable, 各依赖库间以空格分隔;
Name: LD_PRELOAD;
Value: /home/robert/Documents/code/objectdetection/lib/linux_64/libwebp/libwebp.so /home/robert/Documents/code/objectdetection/lib/linux_64/libwebp/libwebpdemux.so /home/robert/Documents/code/objectdetection/lib/linux_64/libwebp/libwebpmux.so /usr/local/lib/libopencv_imgcodecs.so /home/robert/Documents/code/objectdetection/lib/linux_64/libfcn.so /home/robert/ubuntu_env/libopenblas_hh/libopenblas.so
截图如下: