Note that there are some explanatory texts on larger screens.

plurals
  1. POjni undefined symbol error
    primarykey
    data
    text
    <p>I'm trying JNI sample code.<br> (You can get all below sources through github: <a href="https://github.com/pilhoon/jni-test" rel="nofollow">https://github.com/pilhoon/jni-test</a> )</p> <ul> <li>Sample.java</li> </ul> <pre> public class Sample { public native int intMethod(int n); public native boolean booleanMethod(boolean bool); public native String stringMethod(String text); public native int intArrayMethod(int[] intArray); public static void main(String[] args) { System.loadLibrary("sample"); Sample sample = new Sample(); int square = sample.intMethod(5); boolean bool = sample.booleanMethod(true); String text = sample.stringMethod("JAVA"); int sum = sample.intArrayMethod(new int[]{1,1,2,3,5,8,13} ); System.out.println("intMethod: " + square); System.out.println("booleanMethod: " + bool); System.out.println("stringMethod: " + text); System.out.println("intArrayMethod: " + sum); } } </pre> <ul> <li>sample.c</li> </ul> <pre> #include "sample.h" #include &lt;string.h&gt; #ifdef __cplusplus extern "C" { #endif JNIEXPORT jint JNICALL Java_Sample_intMethod (JNIEnv *env, jobject obj, jint num) { return num * num; } JNIEXPORT jboolean JNICALL Java_Sample_booleanMethod (JNIEnv *env, jobject obj, jboolean boolean) { return !boolean; } JNIEXPORT jstring JNICALL Java_Sample_stringMethod (JNIEnv *env, jobject obj, jstring string) { const char *str = (*env)->GetStringUTFChars(env, string, 0); char cap[128]; strcpy(cap, str); (*env)->ReleaseStringUTFChars(env, string, str); return (*env)->NewStringUTF(env, strupr(cap)); } JNIEXPORT jint JNICALL Java_Sample_intArrayMethod (JNIEnv *env, jobject obj, jintArray array) { int i, sum = 0; jsize len = (*env)->GetArrayLength(env, array); jint *body = (*env)->GetIntArrayElements(env, array, 0); for (i=0; iReleaseIntArrayElements(env, array, body, 0); return sum; } void main(){} #ifdef __cplusplus } #endif </pre> <ul> <li>sample.h</li> </ul> <pre> /* DO NOT EDIT THIS FILE - it is machine generated */ #include &lt;jni.h&gt; /* Header for class Sample */ #ifndef _Included_Sample #define _Included_Sample #ifdef __cplusplus extern "C" { #endif /* * Class: Sample * Method: intMethod * Signature: (I)I */ JNIEXPORT jint JNICALL Java_Sample_intMethod (JNIEnv *, jobject, jint); /* * Class: Sample * Method: booleanMethod * Signature: (Z)Z */ JNIEXPORT jboolean JNICALL Java_Sample_booleanMethod (JNIEnv *, jobject, jboolean); /* * Class: Sample * Method: stringMethod * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_Sample_stringMethod (JNIEnv *, jobject, jstring); /* * Class: Sample * Method: intArrayMethod * Signature: ([I)I */ JNIEXPORT jint JNICALL Java_Sample_intArrayMethod (JNIEnv *, jobject, jintArray); #ifdef __cplusplus } #endif #endif </pre> <p>And I compiled these with gcc on CentOS 6.3</p> <pre> prompt$ gcc -c -o sample.o -fPIC sample.c -I /usr/java/jdk1.7.0_07/include/ -I /usr/java/jdk1.7.0_07/include/linux/ prompt$ gcc -shared -o libsample.so sample.o </pre> <p>But when I run 'java Sample', an error occurs.</p> <pre> java: symbol lookup error: /home/ph/tmp/jni/libsample.so: undefined symbol: strupr </pre> <p>How can I fix this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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