C
chris.madden
Hi-
I've successfully execute the JNI examples, and have a nice hello world
program that uses JNI. However, the test examples use the default
package. When I try to move my code to another package, I get
unsatisfied link errors.
Here's the sitch:
I have a package, test.jni that contains JNITest.java. There is a
native method in it called helloWorld() that I attempt to call. To
build the shared object, I did the following:
javah -jni test/jni/JNITest
in the directory I ran the command from I get:
test_0002fjni_0002fJNITest.h
My c file, the originally named jnitest.c is in the same directory.
I compile it all together via:
gcc -shared -olibblah.so -static -lc jnitest.c
-I/usr/java/j2sdk1.4.2_05/include/ -I
/usr/java/j2sdk1.4.2_05/include/linux/
The result is I get libblah.so
libblah.so contains helloWorld:
[root@localhost JNI Test]# nm libblah.so |head -3
00000700 T Java_test_0002fjni_0002fJNITest_helloWorld
000017e8 A _DYNAMIC
000017bc A _GLOBAL_OFFSET_TABLE_
I compile my java file with:
[root@localhost JNI Test]# javac test/jni/JNITest.java
I get no errors or warnings.
I then attempt to run it:
[root@localhost JNI Test]# java test/jni/JNITest
Exception in thread "main" java.lang.UnsatisfiedLinkError: helloWorld
at test.jni.JNITest.helloWorld(Native Method)
at test.jni.JNITest.main(JNITest.java:15)
This works just fine if I have things in the default package. Moving
it to another package, regardless of how I build this thing fail with
the above.
My JNITest.java is below ( and below that, jnitest.c ). Any ideas?
All the examples seem to be in the default package, so I figure I am
probably doing something stupid.
package test.jni;
public class JNITest
{
static {
System.loadLibrary( "blah" );
}
public native void helloWorld();
public static void main ( String[] args )
{
JNITest test = new JNITest();
test.helloWorld();
}
}
// end
jnitest.c:
#include <stdio.h>
#include "test_0002fjni_0002fJNITest.h"
JNIEXPORT void JNICALL Java_test_0002fjni_0002fJNITest_helloWorld
(JNIEnv * env, jobject obj)
{
printf ( "Hello world\n" );
}
I've successfully execute the JNI examples, and have a nice hello world
program that uses JNI. However, the test examples use the default
package. When I try to move my code to another package, I get
unsatisfied link errors.
Here's the sitch:
I have a package, test.jni that contains JNITest.java. There is a
native method in it called helloWorld() that I attempt to call. To
build the shared object, I did the following:
javah -jni test/jni/JNITest
in the directory I ran the command from I get:
test_0002fjni_0002fJNITest.h
My c file, the originally named jnitest.c is in the same directory.
I compile it all together via:
gcc -shared -olibblah.so -static -lc jnitest.c
-I/usr/java/j2sdk1.4.2_05/include/ -I
/usr/java/j2sdk1.4.2_05/include/linux/
The result is I get libblah.so
libblah.so contains helloWorld:
[root@localhost JNI Test]# nm libblah.so |head -3
00000700 T Java_test_0002fjni_0002fJNITest_helloWorld
000017e8 A _DYNAMIC
000017bc A _GLOBAL_OFFSET_TABLE_
I compile my java file with:
[root@localhost JNI Test]# javac test/jni/JNITest.java
I get no errors or warnings.
I then attempt to run it:
[root@localhost JNI Test]# java test/jni/JNITest
Exception in thread "main" java.lang.UnsatisfiedLinkError: helloWorld
at test.jni.JNITest.helloWorld(Native Method)
at test.jni.JNITest.main(JNITest.java:15)
This works just fine if I have things in the default package. Moving
it to another package, regardless of how I build this thing fail with
the above.
My JNITest.java is below ( and below that, jnitest.c ). Any ideas?
All the examples seem to be in the default package, so I figure I am
probably doing something stupid.
package test.jni;
public class JNITest
{
static {
System.loadLibrary( "blah" );
}
public native void helloWorld();
public static void main ( String[] args )
{
JNITest test = new JNITest();
test.helloWorld();
}
}
// end
jnitest.c:
#include <stdio.h>
#include "test_0002fjni_0002fJNITest.h"
JNIEXPORT void JNICALL Java_test_0002fjni_0002fJNITest_helloWorld
(JNIEnv * env, jobject obj)
{
printf ( "Hello world\n" );
}