JNI dependent libraries

后端 未结 6 540
小鲜肉
小鲜肉 2020-12-31 03:52

I\'m running a library via JNI (I didn\'t write it), and internally it calls another DLL. I get an error saying \"Can\'t find dependent libraries\" unless I put the path of

6条回答
  •  一个人的身影
    2020-12-31 04:16

    I had a similar problem. My requirement was to load the following library in a windows environment:

    System.loadLibrary("ibex-java");
    

    In my case, I had configured the -Djava.library.path=C:\projetos\platform\windows\ibex to a folder where all required dlls were stored.

    C:\projetos\platform\windows\ibex>dir
    21/08/2020  14:49              .
    21/08/2020  14:49              ..
    21/08/2020  07:47              ibex
    21/08/2020  14:49           128.108 ibex-java.dll
    21/08/2020  14:49             8.554 ibex-java.dll.a
    21/08/2020  14:49         6.582.641 ibex.dll
    21/08/2020  14:49         5.577.792 ibex.dll.a
    21/08/2020  07:47           938.157 libgcc_s_dw2-1.dll
    21/08/2020  14:49         6.349.752 libibex.a
    21/08/2020  07:47         1.508.122 libstdc++-6.dll
    

    However when I tried to load this library the following error was thrown:

    Caused by: java.lang.UnsatisfiedLinkError: C:\platform\windows\ibex\ibex-java.dll: Can't find dependent libraries
    

    As we can see, all dependent dlls are in the same folder of the library path. However, the single line System.loadLibrary("ibex-java"); couldn't automatically load them. One option to solve this problem was to put the library path in the PATH environment variable of windows, but I didn't like this idea. In my case I find a better solution, find the DLLs dependencies and load these libraries by-hand. For example:

    System.loadLibrary("libgcc_s_dw2-1");
    System.loadLibrary("libstdc++-6");
    System.loadLibrary("ibex");
    System.loadLibrary("ibex-java");
    

提交回复
热议问题