国内下载
https://gitee.com/mirrors/jsoncpp.git
编译安装
cd jsoncpp
mkdir -p build/debug // 或者release
cd build/release
cmake -DCMAKE_BUILD_TYPE=release -DBUILD_STATIC_LIBS=on -DBUILD_SHARED_LIBS=on -DCMAKE_INSTALL_PREFIX=/usr/local ../.. //此命令编译静态库和动态库,设置安装路径为/usr/local
make
sudo make install
使用方法
单个文件使用
g++ file.cpp -I/usr/local -L /usr/local/lib -l/usr/local/lib/libjsoncpp.a
cmake使用
在CMakeList.txt中添加下列语句
find_package(jsoncpp CONFIG REQUIRED)
if(jsoncpp_FOUND)
message(STATUS "Found jsoncpp")
message(STATUS "JSONCPP INCLUDE DIR: ${JSON_INC_PATH}")
endif(jsoncpp_FOUND)
target_include_directories(${NAME}
PUBLIC
${JSONCPP_LIBRARIES}
)
target_link_libraries(${NAME}
PUBLIC
jsoncpp_static # 似乎只用这个就可以
)