Note that there are some explanatory texts on larger screens.

plurals
  1. POJNI - java.lang.UnsatisfiedLinkError - Ubuntu 12.04 LTS
    text
    copied!<p>I understand this question has been asked many times, I have read many post without positive outcome, thus seeking assistance. </p> <p>Original source is <a href="http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html" rel="nofollow">Java Programming with JNI</a></p> <p>I am getting the following error</p> <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no libSample1 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:10) </code></pre> <p>Source code is as follows </p> <p>Sample1.java</p> <pre><code>public class Sample1 { public native int intMethod(int n); public static void main(String[] args) { System.loadLibrary("libSample1"); Sample1 sample = new Sample1(); int square = sample.intMethod(5); System.out.println("intMethod " + square); } } </code></pre> <p>Sample1.h</p> <pre><code>/* DO NOT EDIT THIS FILE - it is machine generated */ #include &lt;jni.h&gt; /* Header for class Sample1 */ #ifndef _Included_Sample1 #define _Included_Sample1 #ifdef __cplusplus extern "C" { #endif JNIEXPORT jint JNICALL Java_Sample1_intMethod (JNIEnv *, jobject, jint); #ifdef __cplusplus } #endif #endif </code></pre> <p>Sample1.cpp</p> <pre><code>#include "Sample1.h" #include &lt;string.h&gt; JNIEXPORT jint JNICALL Java_Sample1_intMethod(JNIEnv *env, jobject obj, jint num) { return num * num ; } </code></pre> <p><strong>OS: Ubuntu 12.04 LTS</strong></p> <p>Compile command </p> <pre><code>g++ -shared -fPIC -I/usr/lib/jvm/jdk1.6.0_45/include -I/usr/lib/jvm/jdk1.6.0_45/include/linux Sample1.cpp -o libSample1.so </code></pre> <p>I also have tried </p> <pre><code>java -Djava.library.path=/home/userid/java_proj/example Sample1 </code></pre> <p>Thank you for the help in advance</p> <p><strong>Update -> Answer:</strong> Javah -jni Sample1 fixed the problem</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload