当我从 Eclipse 中构建我的 Android ndk 项目时,我收到以下错误,引用使用 std::string 作为参数的函数调用,如果我更改为 const char * arg,我会收到类似的错误。我怎样才能摆脱这个,我的 android.mk 附在错误下方:
/Applications/adt-bundle-mac-x86_64/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/JsonPoco/JsonPoco.o: in function jsonParse:jni/JsonPoco.cpp:23: error: undefined reference to 'StoreRefListComplexType::StoreRefListComplexType(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
安卓.mk
LOCAL_PATH := $(call my-dir)
ROOT_PATH := $(LOCAL_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PATH = $(ROOT_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_ARM_MODE := arm
LOCAL_MODULE := JsonPoco # Your own library.
LOCAL_SRC_FILES := JsonPoco.cpp # Your own library source.
LOCAL_CFLAGS := -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY
LOCAL_CPPFLAGS := -frtti -fexceptions
LOCAL_STATIC_LIBRARIES := PocoFoundation \
PocoJSON
include $(BUILD_SHARED_LIBRARY)
还有我的 Application.mk
#Application.mk
APP_STL := gnustl_static
方法调用如下所示,其中 test 是一个 std::string:
void jsonParse(JNIEnv* aEnv, jobject aObj){
std::string test= "jsondata...";
ComplexType* ref = new ComplexType(test);
}
我已经使用方法表将我的 jsonParse 方法定义为可通过 JNI 访问:
static JNINativeMethod methodTable[] = {
{"json_parse", "()V", (void *) jsonParse}};
和接收方法/构造函数:
ComplexType::ComplexType(std::string jsonstring);