在X-Cross平台库中使用JsonCpp。

时间:2022-11-29 12:14:39

I'm making a library in C++ with OpenCV and JsonCpp towards building a library for Android and iOS.

我正在用c++和OpenCV和JsonCpp创建一个库,为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"...

. lang。UnsatisfiedLinkError: dlopen failed: can ' t locate symbol "_ZN4Json6WriterD2Ev" by " libxyzso . "…

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:

我的安卓。可问题是:

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"...

. lang。UnsatisfiedLinkError: dlopen failed: can ' t locate symbol "_ZN4Json6WriterD2Ev" by " libxyzso . "…

EDIT My jsoncpp/Android.mk :

编辑我的jsoncpp / Android。可:

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包括

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)

1 个解决方案

#1


1  

You're not linking against Jsoncpp in your makefile. You should add the following line:

您在makefile中没有链接到Jsoncpp。你应该加上以下一行:

LOCAL_SHARED_LIBRARIES := libJsoncpp

before the last include $(BUILD_SHARED_LIBRARY).

在最后一个包含$(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变量中的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也是如此。

#1


1  

You're not linking against Jsoncpp in your makefile. You should add the following line:

您在makefile中没有链接到Jsoncpp。你应该加上以下一行:

LOCAL_SHARED_LIBRARIES := libJsoncpp

before the last include $(BUILD_SHARED_LIBRARY).

在最后一个包含$(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变量中的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也是如此。