how to avoid UnsatisfiedLinkError when jna is already installed

1,772 views
Skip to first unread message

victor.z...@gmail.com

unread,
Jul 23, 2011, 4:44:39 AM7/23/11
to jna-...@googlegroups.com
Hello,

I get the following error when trying to run the printf example from Getting Started on Ubuntu 10.10 x86_64 with JNA 3.3.0 which I have downloaded from github:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.jna.Native.open(Ljava/lang/String;)J
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.Library$Handler.<init>(Library.java:140)
at com.sun.jna.Native.loadLibrary(Native.java:393)
at com.sun.jna.Native.loadLibrary(Native.java:378)
at HelloWorld$CLibrary.<clinit>(HelloWorld.java:14)
at HelloWorld.main(HelloWorld.java:24)

The problem is that I have another version (3.2.4) of JNA installed. If I uninstall it the example works fine. But what can be done if there is no control over installed packages, how to make sure that such error doesn't happen?

Thanks,
Victor

Timothy Wall

unread,
Jul 23, 2011, 6:19:15 AM7/23/11
to jna-...@googlegroups.com
Make your application use the system jna.jar in its classpath instead of one you're bundling with it, or force it to use the bundled jnidispatch library instead of the system one.

There hasn't been much testing done w/r/t running against a system-installed version of JNA when incompatible versions are involved.

You'd need to force your application to use the same versions of both jar file and jnidispatch library.

victor.z...@gmail.com

unread,
Jul 23, 2011, 6:52:49 AM7/23/11
to jna-...@googlegroups.com
Thank you for a quick answer, Timothy.

How can I force my application to use the bundled jnidispatch library? Do I have to remove the directory containing jnidispatch from jna.library.path?

Best regards,
Victor

Timothy Wall

unread,
Jul 23, 2011, 12:02:20 PM7/23/11
to jna-...@googlegroups.com
If the system jnidispatch is not in LD_LIBRARY_PATH, your app will likely find the bundled one instead. jna.library.path determines where JNA looks for loaded libraries; jna.boot.library.path determines where JNA looks for its own jnidispatch library.

Alternatively, you can make sure the system jna.jar is in your classpath before any that you bundle with it. Either use both the system jar *and* jnidispatch library if available, or use neither.

LD_LIBRARY_PATH normally controls the order of shared library access, and your classpath determines which jna.jar file gets used.

Reply all
Reply to author
Forward
0 new messages