JNI Bundle Native Common Libraries with Clojure Libraries

I am writing a library for clojure that includes native code. How can I merge a common library (as my own dependencies) when deploying clojure libraries to public repositories (e.g. cloes)?

Additional Information:

My project structure looks something like this:

src/
    native/     - C code , C Object files and compiled shared libs
    java/       - Java stuff
    clojure/    - Clojure stuff

I am currently using leineingen. I tried to do:

:jvm-opts [~(str "-Djava.library.path=src/native/:"
          (System/getenv "$LD_LIBRARY_PATH"))]

It works if I'm in a project. However, if I include this project in a dependency, I will get an error UnsatisfiedLink.

+4
source share
1 answer

The answer depends on your specific use case. In the simplest situation, you need to:

  • lib jar, , project.clj native/ :resource-paths.
  • , :native-prefix, , . , "mylib.so" , : [com.foo/bar "1.0.1" :native-prefix ""]
  • , , :native-path project.clj.
  • , :native-path, java.library.path, :jvm-opts, .

sample leiningen project.clj.

, , , , uberjar, , . , lib, . , loadLibraryFromJar NativeUtils. , , ClassLoader , System/load. , , JVM, System/loadLibrary . :

  • lib uberjar , (-> my-lib io/resource io/input-stream (io/copy my-temp-file))
  • java.library.path , , System/setProperty
  • , , .

, .

+4

Source: https://habr.com/ru/post/1609759/


All Articles