前言
在网上找了很多在linux上使用jsoncpp的教程,都是0.5版本的,最后考虑了一下还是用新版本的吧,发个文章记录下编译过程同时帮助一些需要用到新版本的人。
环境搭建
新版本的JsonCpp不再支持scons编译,需要用CMake编译,同时CMake版本必须是3.8以上的,我安装的是3.12.2版本。
CMake安装过程参考文章:
链接: VMware+ubuntu+linux下载及安装(win10) --7. Ubuntu 18.0 中安装cmake 3.12.2.
安装JsonCpp
1、下载
使用wget下载文件,命令如下:
wget https://github.com/open-source-parsers/jsoncpp/archive/master.tar.gz
- 1
2、解压
解压文件:
tar zxvf master.tar.gz
- 1
3、执行CMake
进入解压后的文件夹内,执行cmake
cd jsoncpp-master/
cmake CMakeLists.txt
- 1
- 2
执行完成之后你会发现生成了一个CMakeFile的文件夹,同时
会生成一个Makefile文件。
4、执行make
执行make进行编译
make
- 1
编译完成
5、库与头文件
编译完成后解压文件目录下的lib文件夹下存放了生成的库
编译完成后解压文件目录下的include/json文件夹下存放了头文件
6、布置环境
将生成的库与头文件布置到linux下
make install
- 1
总结
emmm,写完之后突然觉得过程好简单…希望能帮到需要的朋友。
另外给大家提供一个jsoncpp使用方法的文章,里面该有的都有:
C++ Builder 生成 json,Json::StreamWriterBuilder 参数详解.
######################################################
jsoncpp should not be configured & built in the jsoncpp source directory
You must run cmake in a build directory.
For example:
mkdir jsoncpp-Sandbox ; cd jsoncpp-sandbox
git clone https://github.com/open-source-parsers/jsoncpp.git # or download & unpack the source tarball
mkdir jsoncpp-build
this will create the following directory structure
jsoncpp-Sandbox
±-jsoncpp
±-jsoncpp-build
Then you can proceed to configure and build
by using the following commands
cd jsoncpp-build
cmake …/jsoncpp # or ccmake, or cmake-gui
make
NOTE: Given that you already tried to make an in-source build
CMake have already created several files & directories
in your source tree. run ‘git status’ to find them and
remove them by doing:
cd jsoncpp-Sandbox/jsoncpp
git clean -n -d
git clean -f -d
git checkout –
######################################################