JNA with JDK 7 64bit under Windows 7 64bit with mingw-w64 compiled 64 bit DLL: UnsatisfiedLinkError

648 views
Skip to first unread message

Andreas Piening

unread,
Oct 27, 2012, 4:52:38 PM10/27/12
to jna-...@googlegroups.com

Hi JNA-Users,


I just can't get JNA to run under 64bit Windows 7. I created a very simple test project which compiles to a shared library and a JNA project which calls a helloWorld like function. I verrified that it generally works under MacOSX with the exact same source.

I compiled the shared library (DLL) on windows using mingw-w64 with -m64 and it compiles fine. In my test project I used this to make sure that JNA looks in my project working dir:


System.setProperty("jna.library.path",System.getProperty("user.dir"));

System.setProperty("java.library.path",System.getProperty("user.dir"));

System.out.println("JNA library path is: " + System.getProperty("jna.library.path"));


I get the following error while running the Java app with JNA:

JNA library path is: C:\Users\myusername\Documents\NetBeansProjects\JNATest

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libCppDynamicLibraryTest.dll': Das angegebene Modul wurde nicht gefunden.

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)

at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)

at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:199)

at jnatest.LibCppDynamicLibraryTestLibrary.<clinit>(LibCppDynamicLibraryTestLibrary.java:18)

at jnatest.JNATest.main(JNATest.java:22)

Java Result: 1


I thought my problem is related to https://groups.google.com/forum/#!msg/jna-users/Fq5RTlrco2E/sIil8zd5wWEJ but I do allready use the extern statement:


extern "C" {

    void sayNtimesHelloWorld(int n);

}


Please can anyone point me to a possible error I made or a way to debug this?

I've tried hours getting this to work and have no ideas left what to try next.


Thank you very much!

Andreas Piening

Andreas Piening

unread,
Oct 28, 2012, 3:35:20 PM10/28/12
to jna-...@googlegroups.com
After calling depends64 on my DLL file, it turned out that I had unresolved references to "LIBSTDC++-6.DLL" and "LIBGCC_S_SJLJ-1.DLL". After a bit of googling I found a post related to this who said that adding "-static-libgcc -static-libstdc++" solves this by statically including these two references.

It worked for me, so my problem is solved.

Maybe there is a chance to distinguish between a not found DLL file and one with a unresolved reference inside? This may lead to a more meaningful error message, even if this one exactly said what the problem is about.

Should and if how can I mark this issue as resolved?

Thank you,

Andreas Piening

Timothy Wall

unread,
Oct 28, 2012, 4:24:15 PM10/28/12
to jna-...@googlegroups.com
Typically more recent versions of windows will indicate "a dependent module was not found" versus "the requested module was not found". However, there's no easy way of distinguishing different LoadLibrary failures if the system doesn't provide that information.

Andreas Piening

unread,
Oct 28, 2012, 5:30:21 PM10/28/12
to jna-...@googlegroups.com
Hi Timothy,
with more recent you mean Windows 8?

Thank you for the explanation anyway.
Reply all
Reply to author
Forward
0 new messages