【随笔记】NDK 编译开源库 jsoncpp

下载并解压源码

wget https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.4.tar.gz -O jsoncpp_1.9.4.tar.gz
tar -zxvf jsoncpp_1.9.4.tar.gz

在源码根目录创建 Android.mk 文件:

LOCAL_PATH:= $(call my-dir)

SCAN_FILES_PATH  :=  $(LOCAL_PATH)/src/lib_json
SCAN_FILES_SUFFIX := %.cpp %.c %.cc
SCAN_All_Files := $(foreach src_path,$(SCAN_FILES_PATH), $(shell find "$(src_path)" -type f) ) 
SCAN_All_Files := $(SCAN_All_Files:$(SCAN_CPP_PATH)/./%=$(SCAN_CPP_PATH)%)
SCAN_SRC_LIST  := $(filter $(SCAN_FILES_SUFFIX),$(SCAN_All_Files)) 
SCAN_SRC_LIST  := $(SCAN_SRC_LIST:$(LOCAL_PATH)/%=%)

include $(CLEAR_VARS)
LOCAL_MODULE:= jsoncpp
LOCAL_C_INCLUDES := include
LOCAL_SRC_FILES := $(SCAN_SRC_LIST)
LOCAL_CFLAGS := -fstack-protector-all -fomit-frame-pointer -Depl_LINUX
LOCAL_CPPFLAGS := -std=c++11 -fexceptions

include $(BUILD_SHARED_LIBRARY)

在源码根目录创建 Application.mk文件:

APP_STL := c++_static
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19

使用 ndk_build 编译:

lmx@ubuntu:~/work/OpenSource$ cd jsoncpp_1.9.4
lmx@ubuntu:~/work/OpenSource/jsoncpp-1.9.4$ ndk-build NDK_PROJECT_PATH=$(pwd) NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk
[armeabi-v7a] Compile++ thumb: jsoncpp <= json_writer.cpp
[armeabi-v7a] Compile++ thumb: jsoncpp <= json_reader.cpp
[armeabi-v7a] Compile++ thumb: jsoncpp <= json_value.cpp
[armeabi-v7a] SharedLibrary  : libjsoncpp.so
[armeabi-v7a] Install        : libjsoncpp.so => libs/armeabi-v7a/libjsoncpp.so

最后不得不说,jsoncpp 比 libjson-c 好用太多了。

posted @ 2021-08-03 19:50  Love_梦想  阅读(56)  评论(0编辑  收藏  举报