json-c首页: https://github.com/json-c/json-c/wiki
0. 依赖条件
本文采用centos系统编译libjson源码,先提前安装依赖。
#编译器
gcc, clang, or another C compiler
#cmake
cmake>=2.8, >=3.16 recommended
#若要生成文档,还需要doxygen
To generate docs you'll also need:
doxygen>=1.8.13
If you are on a relatively modern system, you'll likely be able to install the prerequisites using your OS's packaging system.
#Install using yum (e.g. CentOs 7.6)
$ yum install -y git
$ yum install -y cmake
$ yum install -y doxygen # optional
$ yum install -y valgrind # optional
1. 下载源码
官方Gibhub下载地址:https://github.com/json-c/json-c/releases
#git clone下载源码包并切换到指定release
$ git clone git@github.com:json-c/json-c.git
$ git checkout json-c-0.14-20200419
#或者直接下载tar包
$ wget https://github.com/json-c/json-c/archive/json-c-0.14-20200419.tar.gz -O json-c.tar.gz
$ tar zxvf json-c.tar.gz
$ mv json-c-json-c-0.14-20200419 json-c
2. 编译安装
#cmake构造自动化脚本
$ mkdir json-c-build && cd json-c-build
$ cmake ../json-c
然后执行编译安装
$ make
$ make test
$ make USE_VALGRIND=0 test # optionally skip using valgrind
$ make install