4 messages in net.java.dev.jna.usersRe: [jna-users] calling a static func...
FromSent OnAttachments
Travis BanksFeb 3, 2009 2:07 pm 
Daniel KaufmannFeb 3, 2009 3:40 pm 
Steve Sobol (JDN)Feb 3, 2009 5:52 pm 
LYou...@gkservices.comFeb 4, 2009 7:55 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] calling a static function from JavaActions...
From:Daniel Kaufmann (dani@gmail.com)
Date:Feb 3, 2009 3:40:53 pm
List:net.java.dev.jna.users

Hello Travis,

jna does not have any special support for C++, only for C. However, in some cases you can call a C++ function from JNA. In your case you first need to understand how is your function exported in the library (.dll/.so) you are trying to call. According to your mail your are trying to call a static function. However, if you specify static for a free function, it means you are asking for Internal linkage, so it is only available in the same C file where you are compiling, so I think it won't be exported so you can't call it from jna. On the other hand if the it is actually a static function of a C++ class, then it can be exported but the name of the exported function is mangled. You can check the exported names for the library using Dependency Walker program in Windows or nm command in linux or cygwin (check "My library mapping causes an UnsatisfiedLinkError" in jna home page). For demangling (showing similar to how you declare it in C++) the function name, in case you are not sure you have found the right function, you can use the option for that in Dependency Walker if you are using Microsoft C++ compiler or c++filt in linux or cygwin. Once you have the mangled name for the function, you can use that name in java or use a *FunctionMapper or InvocationMapper.* Since the parameters are primitive types and arrays and not classes, I believe you should be able to call the function from jna. Regards, Daniel

On 2/3/09, Travis Banks <trav@gmail.com> wrote:

Hello All,

I'm having difficulty declaring a method to call a c++ static function from my library interface file. The native signature is; static void bubble(int *data, int num_data); If I use the following Java interface method; static void bubble(int[] data, int num_data); I get an Illegal Modifier error from my IDE (interfaces can only have public and abstract as modifiers. If I remove 'static' from the interface method I get an UnsatisfiedLinkError when I try to run the program (Error looking up function 'bubble').

How can I call the static function 'bubble' from Java? Thanks for any help you can give me.

- Travis