大家好,我在正在将C++的一些代码通过ndk调用到android项目里面去,但是在出现了一个很奇怪的错误;
/bin/ld: ./obj/local/armeabi/objs/TestNDK2/TestNDK2.o: in function Java_com_example_testndk2_MainActivity_stringTestNdk(_JNIEnv*, _jobject*):jni/TestNDK2.cpp:15: error: undefined reference to 'CFeatureExtract::CFeatureExtract()'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libTestNDK2.so] Error 1
我调用jni的文件代码为:
#include <string.h>
#include "FeatureExtract.h"
#include "Output.h"
#include
jstring
Java_com_example_testndk2_MainActivity_stringTestNdk( JNIEnv* env,
jobject thiz )
{
COutput * pout;
pout = new COutput();
CFeatureExtract *pFtr;
pFtr=new CFeatureExtract();
return (env)->NewStringUTF("Hello from JNI and anbo !");
}
mk文件也编写好了,应该没什么问题,之所以说没问题是因为,我在上面调用了其他cpp文件的 output.cpp和FeatureExtract.cpp等好几个cpp文件,当我把
pFtr=new CFeatureExtract();
这行去掉的时候,会发现不再报错。下面是我的mk的代码:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libFeatureExtract
LOCAL_SRC_FILES := OnlineFtr.cpp OnlineNorm.cpp FeatureExtract.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libOutput
LOCAL_SRC_FILES := LQDFR.cpp Classifier.cpp Output.cpp
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := TestNDK2
LOCAL_SRC_FILES := TestNDK2.cpp
LOCAL_STATIC_LIBRARIES := libFeatureExtract
LOCAL_STATIC_LIBRARIES := libOutput
include $(BUILD_SHARED_LIBRARY)
最后是我CFeatureExtract构造函数的代码:
CFeatureExtract::CFeatureExtract()
{
nmdir = 0;
nwid = zone*zstep;
pNorm = new COnlineNorm;
pFeatr = new COnlineFtr( nwid );
//edit by anbo
trajnorm = NULL;
new_ptnum =0;
new_ptnum_total=0;
strokeEnd=0;
strokeBegin=0;
countStroke=0;
GaussModel_probability =0;
}
下面是.h头文件的部分声明
class CFeatureExtract{
public:
CFeatureExtract();
~CFeatureExtract();
非常想知道到底哪里错了啊!感谢!