Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

JNI problems

Thread view: 
M. Fernandez - 03 Apr 2006 14:47 GMT
Hello,

I am having some problems with using some packages and my JNI application.

I get the famous error

Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: printMe
        at VEViewer.ParticleSLAMProxy.printMe(Native Method)
        at VEViewer.J3DARToolkit.run(J3DARToolkit.java:301)

Where there is package called VEViewer and a class called
ParticleSLAMProxy. This class calls the native method printMe in a c++
file :

//C++ file
JNIEXPORT void JNICALL Java_VEViewer_ParticleSLAMProxy_printMe
(JNIEnv * env, jobject obj)
{   
    printf ("Print Me \n");
}

The library (temp.dll) is found by Java, but the problem is that the
declaration of this native method is not found. I am running this
program from a jar file.

Do you have an idea about what I am doing wrong?

thanks a lot,

Marcelo
Daniel Dyer - 03 Apr 2006 14:39 GMT
> Hello,
>
[quoted text clipped - 23 lines]
>
> Do you have an idea about what I am doing wrong?

JNI uses C calling conventions.  The C++ compiler will mangle your  
function names if you don't wrap your C++ code in the following:

#ifdef __cplusplus
extern "C" {
#endif

/* JNI functions go here. */

#ifdef __cplusplus
}
#endif

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Gordon Beaton - 03 Apr 2006 16:11 GMT
> JNI uses C calling conventions. The C++ compiler will mangle your
> function names if you don't wrap your C++ code in the following:
[quoted text clipped - 8 lines]
> }
> #endif

While your comment is perfectly correct, I'd just like to add that if
you use the exact names and signatures generated by javah and also
include the generated header file, then the functions will already be
declared extern "C".

The OP also needs to watch out for another kind of mangling typical
for MS windows, described here:

 http://en.wikipedia.org/wiki/Name_mangling

Use an inspection tool to see what the library really contains after
compiling.

Finally, it's important to realize that if a package declaration was
used in the Java source, then the header and the native source files
should reflect that (the fully qualified classname should have been
specified when generating the header file).

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

M. Fernandez - 03 Apr 2006 22:26 GMT
Thanks a lot for your help,
 I have found my error with your useful remarks. Actually I has been
accessing the java objects in a bad was. I was calling the JNI functions
with a "static method" and this is obviously wrong (because I have
declared them as object methods).

I just have another question, Do you know an inspector tool for the dll
libraries (Windows, Linux or multi-platform ) ??

thanks,

MArcelo
Gordon Beaton - 04 Apr 2006 08:30 GMT
> I just have another question, Do you know an inspector tool for the
> dll libraries (Windows, Linux or multi-platform ) ??

On Linux and all Unix dialects: objdump and nm.

I don't use Windows, but others have mentioned things like dumpbin,
quickview and depends, which I know nothing about.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Chris Uppal - 04 Apr 2006 09:35 GMT
> I don't use Windows, but others have mentioned things like dumpbin,
> quickview and depends, which I know nothing about.

On Windows, Dependency Walker (aka depends) is my preferred tool.

   http://www.dependencywalker.com/

Free.

   -- chris
Chris Uppal - 04 Apr 2006 10:24 GMT
> The OP also needs to watch out for another kind of mangling typical
> for MS windows, described here:
>
>   http://en.wikipedia.org/wiki/Name_mangling

The JVM is aware of that kind of decoration and checks (on Windows) for both
decorated and undecorated forms of the name:
   _some_function@8
and
   some_function

It does something similar on other OSs.

> Use an inspection tool to see what the library really contains after
> compiling.

Agreed, most especially if one is using an "unusual" compiler

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.