交叉编译JsonCpp
JsonCpp 是一个开源的 C++ 库,用于处理 JSON(JavaScript Object Notation) 数据格式。下面介绍下JsonCpp在Ubuntu下的交叉编译方法。
JsonCpp目前在github上托管,克隆源码:
git clone https://github.com/open-source-parsers/jsoncpp.git
进入jsoncpp文件夹,修改CMakeLists.txt,去掉JsonCpp的测试,因为交叉编译后的可执行文件,在Ubuntu本地运行会出错,将JSONCPP_WITH_TESTS 改成OFF,如下:
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF)
然后创建build文件夹,设置交叉编译器进行编译,这里使用的交叉编译器为arm-linux-gnueabihf:
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ -DCMAKE_BUILD_TYPE=Release
make
注意这里要设置-DCMAKE_BUILD_TYPE=Release,否则编译可能会报错。