I want to call a C program from a Java program using JNI on linux ubuntu.
I am new to this, and I tried the sample program provided at http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html . I have already created .java, .h, .c and .so files. But when I tried to run the program, I get the following error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no Sample1 in java.library.path at java.lang.ClassLoader.loadLibrary (ClassLoader.java:1738) at java.lang.Runtime.loadLibrary0 (Runtime.java:823) at java.lang.System.loadLibrary (System.java:1028) at Sample1.main (Sample1.java:13)
, .so JVM.
.so
, .so LD_LIBRARY_PATH, . .so .so, , .so , LD_LIBRARY_PATH.
LD_LIBRARY_PATH
CentOS , . , JVM . , gcc:
$ javac Sample1.java $ javah Sample1 $ # Include paths must also be specified using -I option in the following gcc command line! $ gcc -shared -I...snip... Sample1.c -o libSample1.so $ # Library path for libSample1.so must also be specified! $ java -Djava.library.path=...path/to/libSample1.so... Sample1
"lib" , JVM - . . Linux.
, .