我正在尝试从另一个类的实例编辑静态变量。但是,我收到一条错误消息,指出我的静态变量是共享库中的未定义符号。
静态类.h
class staticClass{
public:
static int num; //declaration
}
静态类.cpp
#include "staticClass.h"
int num = 0; //definition
... //some functions that use num
主文件
#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 有多么棘手,但我们将不胜感激。