简体   繁体   English

在X-Cross平台库上使用JsonCpp

[英]Using JsonCpp on X-Cross platform library

I'm making a library in C++ with OpenCV and JsonCpp towards building a library for Android and iOS. 我正在使用OpenCV和JsonCpp用C ++创建一个库,以构建适用于Android和iOS的库。

On testing my library for Android, I'm making the JNI files but when I try to load the library I'm getting 在为Android测试我的库时,我正在制作JNI文件,但是当我尝试加载该库时,我得到了

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN4Json6WriterD2Ev" referenced by "libXYZ.so"... java.lang.UnsatisfiedLinkError:dlopen失败:找不到由“ libXYZ.so”引用的符号“ _ZN4Json6WriterD2Ev” ...

and that's because I think I'm not building my Json library very well. 那是因为我认为我没有很好地构建我的Json库。

The library that I use is this one: https://github.com/open-source-parsers/jsoncpp 我使用的库就是这个库: https : //github.com/open-source-parsers/jsoncpp

My Android.mk is: 我的Android.mk是:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on

include $(LOCAL_PATH)/jsoncpp/Android.mk
include /Users/localmac/Desktop/AndroidDevelopment/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

OPENCV_LIB_TYPE:=SHARED

LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_C_INCLUDES += /Users/localmac/mylibrary/OpenCVtry/
LOCAL_C_INCLUDES += /Users/localmac/Desktop/RD/OpenCVtry/Libraries/jsoncpp-master/include

LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_MODULE    := libXYZ
LOCAL_SRC_FILES := androidClass.cpp main.cpp utils.cpp
LOCAL_LDLIBS     += -llog -ldl

include $(BUILD_SHARED_LIBRARY)

I have no idea of how to do this. 我不知道该怎么做。

Thank you in advance. 先感谢您。


EDIT it's not the NDK Compiling's fault. 编辑这不是NDK编译的错误。

Even if I compile the JsonCpp, I get the 即使我编译了JsonCpp,我也得到了

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN4Json6WriterD2Ev" referenced by "libXYZ.so"... java.lang.UnsatisfiedLinkError:dlopen失败:找不到由“ libXYZ.so”引用的符号“ _ZN4Json6WriterD2Ev” ...

EDIT My jsoncpp/Android.mk : 编辑我的jsoncpp / Android.mk:

LOCAL_PATH := $(call my-dir) LOCAL_PATH:= $(调用my-dir)

include $(CLEAR_VARS) 包括$(CLEAR_VARS)

LOCAL_CPP_EXTENSION := .cpp LOCAL_MODULE := libJsoncpp LOCAL_CPP_EXTENSION:= .cpp LOCAL_MODULE:= libJsoncpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/jsoncpp/include LOCAL_C_INCLUDES:= $(LOCAL_PATH)/ jsoncpp / include

LOCAL_SRC_FILES := src/lib_json/json_reader.cpp \\ src/lib_json/json_value.cpp \\ src/lib_json/json_writer.cpp LOCAL_SRC_FILES:= src / lib_json / json_reader.cpp \\ src / lib_json / json_value.cpp \\ src / lib_json / json_writer.cpp

include $(BUILD_SHARED_LIBRARY) 包括$(BUILD_SHARED_LIBRARY)

You're not linking against Jsoncpp in your makefile. 您不会在makefile中链接Jsoncpp。 You should add the following line: 您应该添加以下行:

LOCAL_SHARED_LIBRARIES := libJsoncpp

before the last include $(BUILD_SHARED_LIBRARY) . 在最后一个之前include $(BUILD_SHARED_LIBRARY)

You must specify module names for this variable (and its sister LOCAL_STATIC_LIBRARIES ), that is, what you specified for the LOCAL_MODULE variable. 你必须为这个变量(及其姊妹指定模块名称LOCAL_STATIC_LIBRARIES ),也就是说,你指定的什么LOCAL_MODULE变量。

Also, that spares you from specifiying the includes in the LOCAL_C_INCLUDE variable (as the makefile will include them directly when specifying the library in the variable I mentioned at the top of my post). 另外,这避免了您在LOCAL_C_INCLUDE变量中指定包含内容(因为在我在文章顶部提到的变量中指定库时,makefile将直接包含它们)。

EDIT: For the sake of completeness, I'll add that you can specify multiple libraries like that: 编辑:为了完整起见,我将添加您可以指定多个类似的库:

LOCAL_SHARED_LIBRARIES = libJsoncpp \
                         libOpenCV \
                         ...

and the same goes for LOCAL_STATIC_LIBRARIES . LOCAL_STATIC_LIBRARIES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM