Page 1 of 2

UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 12:51
by BrainDead
I try to use the Java remoteAPi under Mac OS 10.6.8 (V-Rep version: 3.0.3)

I put the libremoteApi.dylib into the java.library.path:
.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

Plugin for remoteApi is installed and I can start it with simExtRemoteApiStart(19999,250,true).

I created a Java-Project with eclipse and added the remoteApi.java and simpleTest.java (changed name to RemoteMain) files.

The project gets compiled but throws the following exception by calling

Code: Select all

int clientID = vrep.simxStart("127.0.0.1",19999,true,true,5000,5);
Exception in thread "main" java.lang.UnsatisfiedLinkError: control.remoteApi.simxStart(Ljava/lang/String;IZZII)I
at control.remoteApi.simxStart(Native Method)
at control.RemoteMain.main(RemoteMain.java:14)

The remoteApi is loaded.

I also compiled the dylib on my computer but get the same exception.

What can I do?

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 13:36
by coppelia
Hello,

Are you sure that the libremoteApi.dylib is found?
Also, in remoteApi.java, in the beginning, try to specify the library name with System.loadLibrary("libremoteApiJava"); or System.loadLibrary("libremoteApiJava.dylib");

Cheers

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 13:55
by BrainDead
I'm sure that the dylib is in the path and is found.

Code: Select all

System.loadLibrary("remoteApiJava");
doesn't throw an exception. The call to simxStart does throw.

When I change

Code: Select all

System.loadLibrary("remoteApiJava");
to

Code: Select all

System.loadLibrary("libremoteApiJava");
I get:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no libremoteApiJava in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at control.remoteApi.<clinit>(remoteApi.java:30)
at control.RemoteMain.main(RemoteMain.java:13)

Same exception with:

Code: Select all

System.loadLibrary("libremoteApiJava.dylib");

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 16:23
by coppelia
Well,

you are right! We probably forgot to clean before building remoteApiJava.dylib after building remoteApi.dylib. Cleaning and rebuilding will solve your problem. Or you can use this on:

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 18:15
by BrainDead
I get same exception with attached lib.

Is any other rebuild neccessary?

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 29 May 2013, 18:21
by coppelia
That is strange.

I tried with the old file and got the same error as you. With this file it works fine. Could you try to recompile it yourself?
In the programming folder type:

make -f remoteApiSharedLibJava_makefile clean
make -f remoteApiSharedLibJava_makefile

You will probably have to adjust the location of the java include folder.

Cheers

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 30 May 2013, 09:24
by BrainDead
Ok, I cleaned and rebuild the remoteApiJava:
Knee-deep-in-the-blood:programming user$ make -f remoteApiSharedLibJava_makefile clean
Cleaning remoteApi/extApi.o remoteApi/extApiPlatform.o remoteApiJava.dylib
Knee-deep-in-the-blood:programming user$ make -f remoteApiSharedLibJava_makefile
Compiling remoteApi/extApi.c to remoteApi/extApi.o
remoteApi/extApi.c: In function ‘jint Java_remoteApi_test(JNIEnv*, _jobject*, jint, _jobject*, _jobject*, jint)’:
remoteApi/extApi.c:5322: warning: unused variable ‘theClientID’
Compiling remoteApi/extApiPlatform.c to remoteApi/extApiPlatform.o
Linking remoteApi/extApi.o remoteApi/extApiPlatform.o to remoteApiJava.dylib
I copied the dylib to the java.library.path:
.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
But still I get the same exception:
java.lang.UnsatisfiedLinkError: control.remoteApi.simxStart(Ljava/lang/String;IZZII)I
at control.remoteApi.simxStart(Native Method)
at control.RemoteMain.main(RemoteMain.java:19)
I put the load call to the constructor to catch a possible exception during load of the library (load or loadLibrary doesn't make a differnce):

Code: Select all

public remoteApi ()
	{
		try 
		{
			System.load("/System/Library/Java/Extensions/libremoteApiJava.dylib");
		} 
		catch (java.lang.UnsatisfiedLinkError e) 
		{
			e.printStackTrace();
		}
	}
	
	/*static{	
		//System.loadLibrary("remoteApiJava");
		System.load("/System/Library/Java/Extensions/libremoteApiJava.dylib");
	}*/
No exception is thrown during loading.

The exception ist thrown when I call a native function of the library:

Code: Select all

try 
		{
			clientID = vrep.simxStart("127.0.0.1",19999,true,true,5000,5);
		} 
		catch (java.lang.UnsatisfiedLinkError e) 
		{
			e.printStackTrace();
		}
I catch the exception but get no more details then above. The stack trace is null.

Do the *.cpp method signatures exactly match those in the *.h file?
The spec to the UnsatisfiedLinkError says:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 30 May 2013, 15:12
by coppelia
Hello again,

Difficult to debug since it is working here. But maybe try to append extern "C" in front of each JNIEXPORT as suggested in this post.

Cheers

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 30 May 2013, 16:14
by coppelia
Can you try with following file? You might have to rename the library to what you had previously, and make sure the correct library is loaded.

Re: UnsatisfiedLinkError Mac OS by calling simxStart

Posted: 31 May 2013, 08:30
by BrainDead
Thanks a lot!

The new lib is working.