Java: load shared libraries with dependencies

前端 未结 6 1836
别那么骄傲
别那么骄傲 2021-02-14 16:43

I am wrapping a shared library (written in C) with Java using JNA. The shared library is written internally, but that library uses functions from another external library, which

6条回答
  •  后悔当初
    2021-02-14 17:22

    There is yet another solution for that. You can dlopen directly inside JNI code, like this:

    void loadLibrary() {
      if(handle == NULL) {
        handle = dlopen("libname.so", RTLD_LAZY | RTLD_GLOBAL);
        if (!handle) {
          fprintf(stderr, "%s\n", dlerror());
          exit(EXIT_FAILURE);
        }
      }
    }
    
    ...
    ...
    
    loadLibrary();
    

    This way, you will open library with RTLD_GLOBAL.

    You can find detailed description here: http://www.owsiak.org/?p=3640

提交回复
热议问题