9 messages in net.java.dev.jna.usersRe: [jna-users] UnsatisfiedLinkError...
FromSent OnAttachments
Nicolas VienneDec 12, 2007 2:48 am 
Timothy WallDec 12, 2007 4:42 am 
Nicolas VienneDec 12, 2007 5:31 am 
Timothy WallDec 12, 2007 6:10 am 
Nicolas VienneDec 12, 2007 7:02 am 
Timothy WallDec 12, 2007 7:29 am 
Timothy WallDec 12, 2007 7:55 am 
Nicolas VienneDec 12, 2007 8:12 am 
Timothy WallDec 12, 2007 8:30 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] UnsatisfiedLinkError withActions...
From:Timothy Wall (twal@dev.java.net)
Date:Dec 12, 2007 4:42:41 am
List:net.java.dev.jna.users

You have two options.

1) pass a StdCallFunctionMapper to Native.loadLibrary as an option. This will convert "add" to "add@8", which is the default symbol generated for your add function with the stdcall convention.

2) tell your compiler/linker to generate undecorated symbols. With gcc, this is "-Wl,--add-stdcall-alias".

In addition, make sure you have extern "C" int add(int, int); ^^^^^^^^^^

as the function declaration if compiling with a C++ compiler. Otherwise the compiler mangles the name to include type information, and JNA does not automatically handle that.

On Dec 12, 2007, at 5:48 AM, Nicolas Vienne wrote:

Hello everybody,

I have a little problem while trying to use JNA with my own DLL. I defined the function : int add(int a, int b) I tried many mappings (StdCallLibrary, Library, etc ...), for instance: public interface DllFunction extends StdCallLibrary { DllFunction INSTANCE = (DllFunction)Native.loadLibrary("DllTest", DllFunction.class); public int add(int a, int b); } but every time, the call: DllFunction.INSTANCE.add(12, 30) raises an "java.lang.UnsatisfiedLinkError: Cannot locate function 'add'".

I tried also to pass an StdCallFunctionMapper but it fixed nothing.

After taking a look at the dll file with depends i found that the function was named "?add@@YAHHH@Z", and thus: NativeLibrary nl = NativeLibrary.getInstance("DllTest"); Function f = nl.getFunction("?add@@YAHHH@Z"); Object[] a = {12,30}; System.out.println(f.invokeInt( a )); works fine.

I wonder if there is a way to do it the "right" way ie with the interface mapping ?

Thank you for any help !