Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
help please! for attempt at JNI
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Guest, post: 535913"] hi all, it just isn't working for me! i am attempting a very simple program that calls a native method. i am pretty sure i am following all the correct steps, but it still doesn't work. error message is: Exception in thread "main" java.lang.UnsatisfiedLinkError: no Native in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403) at java.lang.Runtime.loadLibrary0(Runtime.java:788) at java.lang.System.loadLibrary(System.java:832) at Native.<clinit>(Native.java:21) step 1: write and compile the class public class Native { public Native() { int x; int y; System.out.println("about to call calc"); x = calc(10, 30); y = calc(11, 40); System.out.println("x is " + x); System.out.println("y is " + y); } native int calc(int x, int y); public static void main(String[] args) { new Native(); } static { System.out.println("about to load library ..."); System.out.println(System.getProperty("java.library.path")); System.loadLibrary("Native"); System.out.println("library loaded ..."); } } step 2: generate the header file, create the c source, then compile and create a shared library. I am running on redhat 9.0, so, javah -jni Native gcc -c Native.c ld -shared Native.o -o Native.so #include <jni.h> #include "Native.h" JNIEXPORT jint JNICALL Java_Native_calc (JNIEnv *env, jobject th, jint x, jint y) { jint z = x * y; return z; } int main() { printf("5 x 5 is %d", Java_Native_calc(NULL, NULL, 5, 5)); } step 3: at this point, Native.so exists in the current directory. so run the java program, including the current directory as the library path java -Djava.library.path=. Native which results in the UnsatisifiedLinkError what am i doing wrong? c [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
help please! for attempt at JNI
Top