How to use dylib file?

I am trying to install robot simulation software called V-Rep, where for remote robot simulation I need the remoteApi.java and remoteApiJava.dylib . I cannot figure out how to use the dylib file. The error I get when creating a project:

 Exception in thread "main" java.lang.UnsatisfiedLinkError: no remoteApiJava in java.library.path 

I tried to run the dylib file directly in the terminal, it did not work.

I put it in /projectPath/lib/ and added it as a build path in eclipse, it didn't work

I also tried setting the environment variable in run config, DYLD_LIBRARY_PATH = /projectPath/lib/ didn't work either.

What did I do there?

+4
source share
1 answer

To load your own library in java, you can use one of the following methods:

Using System.load

You can use the System.load(String filename) function to load the library directly from the file system, you must specify the absolute path name of your native library. For example, System.load("/System/libraries/libSomeNative.dylib") .

Using System.loadLibrary

Alternatively, you can use the System.loadLibrary(String libName) function to load your own library. This method is system dependent and requires that you specify java.library.path with the paths where your native library is located. In your case, you can use -Djava.library.path=/path/toNativeLib/ as the java argument.

Alternatively, since you are trying to use Eclipse , you can also specify this path as follows: Right-click on the project> Properties. Then select the Java Build path and go to the "Source" tab, here, if you expand the source folder, you can set the Native library folder that defines the path of your native library:

enter image description here

Since this call is system-dependent, note that the parameter libName System.loadLibrary(String libName) not the name of the native library directly. On MAC OS X (it differs from other OSs), it uses the lib prefix and the .dylib suffix on libName , so you must use SomeNative as libName .

Summarize, for example, to load /System/libraries/libSomeNative.dylib , you must specify java.library.path=/System/libraries/ , as described above, and make a call to System.loadLibrary("SomeNative") .

+3
source

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


All Articles