Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dylib file?

I am trying to install a robot simulation software called V-Rep where to remotely simulate the robots, I need to have remoteApi.java and remoteApiJava.dylib files. I can't seem to figure out how to use the dylib file. the error I get when I build the project:

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

I tried running the dylib file directly in terminal, didn't work.

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

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

What did I do wrong there?

like image 988
Bonk Avatar asked Mar 24 '23 00:03

Bonk


1 Answers

To load a native library in java you can use one of these approaches:

Using System.load

You can use System.load(String filename) function to load a 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

You can alternatively use System.loadLibrary(String libName) function to load a native library. This method is system dependent and require 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 a java argument.

Alternatively since you're trying with Eclipse you can specify also this path in the follow way: Right click on project > Properties. Then select Java Build path and click on Source tab, here if you expand your source folder you can set the Native library location specifying the path of your native library:

enter image description here

Since this call is system dependent note that libName parameter of the System.loadLibrary(String libName) is not the native library name directly. In MAC OS X (it works diferent on others OS) it use the lib prefix and the .dylib suffix on the libName, so to specify libSomeNative.dylib you've to use SomeNative as libName.

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

like image 90
albciff Avatar answered Apr 05 '23 14:04

albciff