我想從另一個類的實例編輯一個靜態變量。然而,我得到一個錯誤,說我的靜態變量是我的共享庫中的一個未定義的符號。JNI靜態變量是未定義的符號
staticClass.h
class staticClass{
public:
static int num; //declaration
}
staticClass.cpp
#include "staticClass.h"
int num = 0; //definition
... //some functions that use num
的main.cpp
#include "staticClass.h"
#include <jni.h>
#include "main.h" //this is the header file for the JNI, I will not include this unless someone finds it necessary because all these variables are made up for clarity
JNIEXPORT jint JNICALL Java_main_foo(JNIEnv *env, jobject thisobj, jint someInt){
staticClass example;
int intIWant = (int)someint;
example.num = intIWant;
printf("%d\n",example.num);
}
這是錯誤消息:
Exception in thread "main" java.lang.UnsatisfiedLinkError: .../libfoo.so: .../libfoo.so: undefined symbol: _ZN5staticClass9numE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1935)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1860)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1850)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at tcr.<clinit>(tcr.java:9)
所以是的,我知道有多棘手的UnsatisfiedLinkError可以,但任何幫助將不勝感激。
@AlexCohn有我的電腦上沒有JNI/Android.mk文件。 –