JNA - java.lang.UnsatisfiedLinkError on Ubuntu

1,291 views
Skip to first unread message

Damien Gallagher

unread,
Oct 2, 2017, 9:47:07 AM10/2/17
to Java Native Access
I am trying to call my shared library on Ubuntu on an Amazon EC2 instance
The same code works 100% fine on windows but on Ubuntu - I am getting a java.lang.UnsatisfiedLinkError when I try to run it 

When I run ldd on my shared library - all dependencies appear to be satisfied

 
   root@ip-172-31-14-36:/var/lib/tomcat8/conf# ldd /tmp/dll/linux/v1/release/myConvertor.so
            linux
-vdso.so.1 =>  (0x00007ffed4ffd000)
            libQt5Widgets
.so.5 => /tmp/dll/linux/v1/release/libQt5Widgets.so.5 (0x00007fa81daff000)
            libQt5Gui
.so.5 => /tmp/dll/linux/v1/release/libQt5Gui.so.5 (0x00007fa81d2ec000)
            libQt5Xml
.so.5 => /tmp/dll/linux/v1/release/libQt5Xml.so.5 (0x00007fa81d0b0000)
            libQt5Network
.so.5 => /tmp/dll/linux/v1/release/libQt5Network.so.5 (0x00007fa81cd57000)
            libQt5Core
.so.5 => /tmp/dll/linux/v1/release/libQt5Core.so.5 (0x00007fa81c610000)
            libpthread
.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa81c3e6000)
            libstdc
++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa81c064000)
            libm
.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa81bd5a000)
            libgcc_s
.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa81bb44000)
            libc
.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa81b77a000)
            libgobject
-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fa81b526000)
            libgthread
-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fa81b324000)
            librt
.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa81b11c000)
            libglib
-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fa81ae0a000)
            libXext
.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fa81abf8000)
            libX11
.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fa81a8be000)
            libGL
.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007fa81a64b000)
            libicui18n
.so.54 => /usr/lib/libicui18n.so.54 (0x00007fa81a1f7000)
            libicuuc
.so.54 => /usr/lib/libicuuc.so.54 (0x00007fa819e66000)
            libicudata
.so.54 => /usr/lib/libicudata.so.54 (0x00007fa81843c000)
            libdl
.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa818238000)
           
/lib64/ld-linux-x86-64.so.2 (0x0000559ebb9c1000)
            libffi
.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fa81802f000)
            libpcre
.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fa817dbf000)
            libxcb
.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fa817b9c000)
            libexpat
.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fa817973000)
            libxcb
-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007fa817770000)
            libxcb
-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007fa81756c000)
            libxcb
-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fa817365000)
            libxshmfence
.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007fa817162000)
            libglapi
.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007fa816f32000)
            libXdamage
.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fa816d2f000)
            libXfixes
.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fa816b29000)
            libX11
-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007fa816926000)
            libxcb
-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007fa81670d000)
            libxcb
-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007fa816508000)
            libXxf86vm
.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fa816301000)
            libdrm
.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007fa8160f0000)
            libXau
.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fa815eeb000)
            libXdmcp
.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fa815ce5000)




My code to load the shared library is as follows

    String dllLocation = "/tmp/dll/linux/v1/release/myConvertor.so";
    canvasConversionInterface
= (CanvasConversionInterface) Native.loadLibrary(dllLocation, CanvasConversionInterface.class);



I have the following system properties set on tomcat

    jna.library.path="/tmp/dll/linux/v1/release"
    jna
.debug_load=true



Here is the error I get when I try call that line above to load the shared library

   
 Looking in classpath from WebappClassLoader
      context
: ROOT
     
delegate: false
   
----------> Parent Classloader:
    java
.net.URLClassLoader@52d278a0
     
for /com/sun/jna/linux-x86-64/libjnidispatch.so
   
Found library resource at jar:file:/var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/jna-4.5.0.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
   
Looking for library '/tmp/dll/linux/v1/release/myConvertor.so'
   
Adding paths from jna.library.path: "/tmp/dll/linux/v1/release"
   
Trying /tmp/dll/linux/v1/release/myConvertor.so
   
Adding system paths: [/usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, /lib64, /usr/lib, /lib, /usr/lib/x86_64-linux-gnu/libfakeroot, /usr/lib/x86_64-linux-gnu/mesa]
   
Trying /tmp/dll/linux/v1/release/myConvertor.so
   
Looking for version variants
   
Looking in classpath from WebappClassLoader
      context
: ROOT
     
delegate: false
   
----------> Parent Classloader:
    java
.net.URLClassLoader@52d278a0
     
for /tmp/dll/linux/v1/release/myConvertor.so
   
2017-10-02 13:27:21 [jmsNewPublicationQueueMessageListenerContainer-1] WARN  o.s.j.l.DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
    java
.lang.UnsatisfiedLinkError: Unable to load library '/tmp/dll/linux/v1/release/myConvertor.so': Native library (tmp/dll/linux/v1/release/myConvertor.so) not found in resource path ([...

...

I can verify that all paths mentioned above are accurate

Can anyone offer any ideas on what I could try next to try and get this working?

Thank you
Damien

Matthias Bläsing

unread,
Oct 2, 2017, 2:52:04 PM10/2/17
to jna-...@googlegroups.com
Hi Damien,

Am Montag, den 02.10.2017, 06:47 -0700 schrieb Damien Gallagher:
> I am trying to call my shared library on Ubuntu on an Amazon EC2
> instance
> The same code works 100% fine on windows but on Ubuntu - I am getting
> a java.lang.UnsatisfiedLinkError when I try to run it 
>
> I have the following system properties set on tomcat
>
>     jna.library.path="/tmp/dll/linux/v1/release"
>     jna.debug_load=true
>

please check if tmp is mounted noexec. If so, please check with if it
works without that.

If that does not work, please try to reproduce this without tomcat and
create a stand-alone sample.

Greetings

Matthias

Damien Gallagher

unread,
Oct 2, 2017, 3:45:29 PM10/2/17
to jna-...@googlegroups.com
Hi Matthias

How would I go about checking if tmp is mounter noexec? 
Would this be common for Ubuntu?
Sure thing - I will work on a stand alone sample

Thanks
Damien



--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/yUKCLtnACkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthias Bläsing

unread,
Oct 2, 2017, 3:58:42 PM10/2/17
to jna-...@googlegroups.com
Hi Damien,


Am Montag, den 02.10.2017, 20:45 +0100 schrieb Damien Gallagher:
> How would I go about checking if tmp is mounter noexec? 

Run on the "mount" command on CLI. Look if there is an entry for /tmp.

> Would this be common for Ubuntu?

No.

> Sure thing - I will work on a stand alone sample

And check if changing the loading call to:

canvasConversionInterface = (CanvasConversionInterface) Native.loadLibrary("myConvertor", CanvasConversionInterface.class);

helps. You are settig the jna.library.path, so you don't need the full
qualified path.

HTH

Matthias

Damien Gallagher

unread,
Oct 2, 2017, 4:03:22 PM10/2/17
to jna-...@googlegroups.com
HI Matthias

Nothing for the /tml directory when I run the mount command
Yes I specified the path with no prefix and no extension but the same issue occured.

I will work on the sample and let you know how I get on with it

Thank you
Damien


Matthias

Timothy Wall

unread,
Oct 2, 2017, 4:59:01 PM10/2/17
to jna-...@googlegroups.com
Run with -Djna.debug_load=true and -Djna.debug_load.jna=true.  That will cause JNA to emit where it's looking for libraries and what it finds.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+unsubscribe@googlegroups.com.

Damien Gallagher

unread,
Oct 2, 2017, 5:18:36 PM10/2/17
to jna-...@googlegroups.com
Hi Timothy

I tried that and the paths it emits are shown in the original post

Thank you
Damien

Timothy Wall

unread,
Oct 3, 2017, 9:56:20 AM10/3/17
to jna-...@googlegroups.com
If you supply "myConverter" as the name of your library, JNA will attempt to find "libmyConverter.so".  Providing the absolute path as in your example will avoid any modifications of the filename path, so it's odd that that's not working if that path exists and is an architecture-appropriate library.

Damien Gallagher

unread,
Oct 3, 2017, 10:04:35 AM10/3/17
to jna-...@googlegroups.com
Hi Timothy

Yes I have noticed that too and saw a few comments on it
Interesting I tried with OpenJDK and it loaded the library ok but created a heap dump on the first operation
If I used Oracle JDK 8 - it won't load the library at all

I am using version 4.5.0 of JNA

Thanks
Damien

Timothy Wall

unread,
Oct 3, 2017, 11:14:41 AM10/3/17
to jna-...@googlegroups.com

Damien Gallagher

unread,
Oct 3, 2017, 11:52:47 AM10/3/17
to jna-...@googlegroups.com
No signals are used

All methods are relatively simple to be honest

I have a standalone project and instructions for running on a ubuntu server on Amazon EC2 if that would help with debugging?

Damien Gallagher

unread,
Oct 4, 2017, 8:43:41 AM10/4/17
to Java Native Access
Hi

This is the latest output when I try run my code
Trying (via loadLibrary) jnidispatch
Looking in classpath from jdk.internal.loader.ClassLoaders$AppClassLoader@ba8a1dc for /com/sun/jna/linux-x86-64/libjnidispatch.so
Found library resource at jar:file:/home/ubuntu/testing/CanvasTesting.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Trying /tmp/jna-3506402/jna3748024654198004224.tmp
Found jnidispatch at /tmp/jna-3506402/jna3748024654198004224.tmp
Looking for library 'myConverter'
Adding paths from jna.library.path: /home/ubuntu/testing/release/
Trying /home/ubuntu/testing/release/libmyConverter.so
Adding system paths: [/usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, /lib64, /usr/lib, /lib, /usr/lib/x86_64-linux-gnu/libfakeroot, /usr/lib/x86_64-linux-gnu/mesa]
Trying /home/ubuntu/testing/release/libmyConverter.so
Looking for version variants
Trying /home/ubuntu/testing/release/libmyConverter.so.1.0
Looking in classpath from jdk.internal.loader.ClassLoaders$AppClassLoader@ba8a1dc for myConverter
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'myConverter': Native library (linux-x86-64/libmyConverter.so) not found in resource path (CanvasTesting.jar)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:303)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:427)
        at com.sun.jna.Library$Handler.<init>(Library.java:179)
        at com.sun.jna.Native.loadLibrary(Native.java:569)
        at com.sun.jna.Native.loadLibrary(Native.java:544)
        at com.adalo.canvas.dll.conversion.AdaloConversionServiceImpl.instantiateConversonLibrary(AdaloConversionServiceImpl.java:68)
        at com.adalo.AdaloMain.getPageText(AdaloMain.java:78)
        at com.adalo.AdaloMain.main(AdaloMain.java:49)

I have verified that both /home/ubuntu/testing/release/libmyConverter.so and /home/ubuntu/testing/release/libmyConverter.so.1.0 exist
Also running ldd on these files shows all dependencies exist


I have also copied the libraries to the lib folder but same error is returned
For the line Native library (linux-x86-64/libmyConverter.so) not found in resource path (CanvasTesting.jar)
Is it possible to not look in the jar but look elsewhere for the library?

Matthias
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/yUKCLtnACkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/yUKCLtnACkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.

Timothy Wall

unread,
Oct 4, 2017, 9:53:47 PM10/4/17
to jna-...@googlegroups.com
Each of the "Trying " lines below is encountering an UnsatisfiedLinkError.  It'd be useful to see the output of each one, since the library files themselves _are_ being found.  You'd need to tweak NativeLibrary.java to do so (which would be useful debug output anyway).

Looking for library 'myConverter'
Adding paths from jna.library.path: /home/ubuntu/testing/release/
Trying /home/ubuntu/testing/release/libmyConverter.so
Adding system paths: [/usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, /lib64, /usr/lib, /lib, /usr/lib/x86_64-linux-gnu/libfakeroot, /usr/lib/x86_64-linux-gnu/mesa]
Trying /home/ubuntu/testing/release/libmyConverter.so
Looking for version variants
Trying /home/ubuntu/testing/release/libmyConverter.so.1.0
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+unsubscribe@googlegroups.com.

Damien Gallagher

unread,
Oct 5, 2017, 8:47:36 AM10/5/17
to Java Native Access
Hi 

I tweaked the Native and NativeLibrary classes to ad more output and here is what I get now
Native: Trying (via loadLibrary) jnidispatch
Native: 1. UnsatisfiedLinkError:java.lang.UnsatisfiedLinkError: no jnidispatch in java.library.path
Native: Platform.RESOURCE_PREFIX:linux-x86-64
Native: jniDispathName:libjnidispatch.so
Native: libName:/com/sun/jna/linux-x86-64/libjnidispatch.so
Native: Looking in classpath from sun.misc.Launcher$AppClassLoader@55f96302 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Native: Found library resource at jar:file:/home/ubuntu/testing/CanvasTesting.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Native: Trying /tmp/jna-3506402/jna4864993757680172292.tmp
Native: Found jnidispatch at /tmp/jna-3506402/jna4864993757680172292.tmp
NativeLibrary: libraryName:/home/ubuntu/testing/release/myConverter.so
NativeLibrary: options:{classloader=sun.misc.Launcher$AppClassLoader@55f96302, calling-convention=0}
NativeLibrary: Looking for library '/home/ubuntu/testing/release/myConverter.so'
NativeLibrary: isAbsolutePath:true
NativeLibrary: openFlags:-1
NativeLibrary: webstartPathnull
NativeLibrary: customPathsnull
NativeLibrary: Adding paths from jna.library.path: /home/ubuntu/testing/release
NativeLibrary: libraryName/home/ubuntu/testing/release/myConverter.so
NativeLibrary: searchPath[/home/ubuntu/testing/release]
NativeLibrary: libraryPath/home/ubuntu/testing/release/myConverter.so
NativeLibrary: Trying /home/ubuntu/testing/release/myConverter.so
NativeLibrary: 1 UnsatisfiedLinkError:java.lang.UnsatisfiedLinkError: /home/ubuntu/testing/release/myConverter.so: undefined symbol: _ZTVN2cv12_OutputArrayE
NativeLibrary: Adding system paths: [/usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, /lib64, /usr/lib, /lib, /usr/lib/x86_64-linux-gnu/libfakeroot, /usr/lib/x86_64-linux-gnu/mesa]
NativeLibrary: 2 libraryPath/home/ubuntu/testing/release/myConverter.so
NativeLibrary: Trying /home/ubuntu/testing/release/myConverter.so
NativeLibrary: 2 UnsatisfiedLinkError:java.lang.UnsatisfiedLinkError: /home/ubuntu/testing/release/myConverter.so: undefined symbol: _ZTVN2cv12_OutputArrayE
NativeLibrary: Here 1
NativeLibrary: Looking for version variants
NativeLibrary: 3 libraryPath:null
Native: Looking in classpath from sun.misc.Launcher$AppClassLoader@55f96302 for /home/ubuntu/testing/release/myConverter.so
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library '/home/ubuntu/testing/release/myConverter.so': Native library (home/ubuntu/testing/release/myConverter.so) not found in resource path ([file:/home/ubuntu/testing/CanvasTesting.jar])
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:317)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:443)
        at com.sun.jna.Library$Handler.<init>(Library.java:179)
        at com.sun.jna.Native.loadLibrary(Native.java:550)
        at com.sun.jna.Native.loadLibrary(Native.java:524)
        at com.adalo.canvas.dll.conversion.AdaloConversionServiceImpl.instantiateConversonLibrary(AdaloConversionServiceImpl.java:59)
        at com.adalo.AdaloMain.getPageText(AdaloMain.java:79)
        at com.adalo.AdaloMain.main(AdaloMain.java:50)


Perhaps from looking at this line
 - 2 UnsatisfiedLinkError:java.lang.UnsatisfiedLinkError: /home/ubuntu/testing/release/myConverter.so: undefined symbol: _ZTVN2cv12_OutputArrayE

It may be an issue with the library itself?
Should I try and get the library recompiled?

Thank you
Damien
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.

Damien Gallagher

unread,
Oct 5, 2017, 4:05:19 PM10/5/17
to Java Native Access
Hi

We have made a breakthrough
The issue was with the shared library and it was using OpenCV
After talking with the C++ developer - we figured out that the OpenCV dependency could be removed from the Library
Once we removed this and tried again - everything worked perfectly

Thank you runedelve, Timothy and Matthias (as always) for your help on this
I would have given up before now only for the great support I have received here

Thank you
Damien
Reply all
Reply to author
Forward
0 new messages