UnsatisfiedLinkError for native function of inner class

Hello,

I have a problem with native functions of inner classes.

Here is the code:

class Outer

{

publicstaticclass Inner{

nativepublicvoid innerFct();

}

publicstaticvoid main(String[] args){

Inner i =new Inner();

i.innerFct();

}

static{

System.loadLibrary("OuterInner");

}

}

javah generates this

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class Outer_Inner */

#ifndef _Included_Outer_Inner

#define _Included_Outer_Inner

#ifdef __cplusplus

extern"C"{

#endif

/*

* Class:Outer_Inner

* Method:innerFct

* Signature: ()V

*/

JNIEXPORTvoid JNICALL Java_Outer_Inner_innerFct

(JNIEnv *, jobject);

#ifdef __cplusplus

}

#endif

#endif

Dumping shows that the symbol is in the dll

$ /cygdrive/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 8/VC/bin/amd64

/link.exe /dump /exports OuterInner.dll

Microsoft (R) COFF/PE Dumper Version 8.00.50727.42

Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file OuterInner.dll

File Type: DLL

Section contains the following exports for OuterInner.dll

00000000 characteristics

4581C2A7 time date stamp Thu Dec 14 22:31:19 2006

0.00 version

1 ordinal base

1 number of functions

1 number of names

ordinal hint RVAname

10 00001000 Java_Outer_Inner_innerFct

Summary

3000 .data

1000 .pdata

3000 .rdata

1000 .reloc

7000 .text

and the dll gets loaded without a problem, but at execution I get

$ java Outer

Exception in thread "main" java.lang.UnsatisfiedLinkError: innerFct

at Outer$Inner.innerFct(Native Method)

at Outer.main(Outer.java:13)

I am on Windows XP64 on a Turion, and the Java version is:

$ java -version

java version "1.5.0_10"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)

Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_10-b03, mixed mode)

[3037 byte] By [irbafa] at [2007-11-26 12:39:42]
# 1

Since the static nested class name is Outer$Inner then the JNI function name for innerFct should be:

Java_Outer_00024Inner_innerFct

(_00024 is the unicode translation for $)

You should read on [url http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp615]Resolving Native Method Names[/url].

Regards

jfbrierea at 2007-7-7 16:10:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
This is a javah bug in the Java 5 SDK. It is fixed in the Java 6 SDK, btw.Not sure what reading that reference will do to help him with the problem, unless you are suggesting he manually edit the code that is generated by javah. Perhaps it would be better to suggest the devs read it
mjdalpeea at 2007-7-7 16:10:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

> This is a javah bug in the Java 5 SDK. It is fixed in the Java 6 SDK, btw.

Thanks for the info.

> Not sure what reading that reference will do to help him with the problem,

> unless you are suggesting he manually edit the code that is generated by javah

That is what I meant indeed. There is nothing wrong in doing this btw.

I allways use javah as a "one shot" step in my projects.

Then I allways manually edit the generated h file (I rearrange it a bit).

Regards

jfbrierea at 2007-7-7 16:10:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...