Friday 18 May 2012

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function

So who is the culprit?! I tell you who it is, you are getting below exception;
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'chmod':
The specified procedure could not be found.

 at com.sun.jna.Function.<init>(Function.java:129)
 at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:250)
 at com.sun.jna.Library$Handler.invoke(Library.java:191)
 at $Proxy0.chmod(Unknown Source)

because the native function mentioned in your exception is not found in your native library, Or your native functions are not exposed outside the premiss of your library.

To inspect your native library, for example if you have done something similar to previous post, for windows enviroment I recommed downloading Dependency Walker or .*nix users using gdb core to inspect the output library.

If you cannot see the mentioned function, chances are you compiled your native library as shown in previous post or as shown below;
gcc -o native.dll native.c
Solution
Use the -shared flag to resolve this. Now compile your library like this;
gcc -shared -mno-cygwin -Wall -o native.dll native.c
remove -mno-cygwin -Wall if you are not using cygwin on windows. Now go grab a cuppa coffee and see your natives in action. And oh, don't forget to move the library to your classpath.

No comments:

Post a Comment