ubunt下安装参考
http://www.360doc.com/content/14/0725/08/14679766_396880822.shtml
编写测试
- main.cpp
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include "json/json.h"
using namespace std;
int main()
{
string test ="{\"id\":1,\"name\":\"kurama\"}";
Json::Reader reader;
Json::Value value;
if(reader.parse(test,value))
{
if(!value["id"].isNull())
{
cout<<value["id"].asInt()<<endl;
cout<<value["name"].asString()<<endl;
}
}
return 0;
}
- CMakeLists.txt
PROJECT (FUN)
set(APP_SRC main.cpp)
set(exe_name test)
set(lib_name json_linux-gcc-5.4.0_libmt)
# 库头文件所在目录
set(lib_inc /home/ding/Downloads/jsoncpp-src-0.5.0/include CACHE PATH "include of ")
# 库文件所在目录
set(lib_dir /home/ding/Downloads/jsoncpp-src-0.5.0/libs/linux-gcc-5.4.0 CACHE PATH "directory of .lib")
# 在这里动态库与静态库的设置是一样的
# 指定头文件的搜索路径
include_directories(${lib_inc})
# 指定库文件的搜索路径
link_directories(${lib_dir})
# 可执行文件生成在 ./bin下面
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# 生成可执行文件
add_executable(${exe_name} ${APP_SRC})
# 可执行文件 需要链接 库
target_link_libraries(${exe_name} ${lib_name})
- 运行脚本travis.sh
#!/usr/bin/env sh
#set -evx
#env | sort
EXE_DIR=./bin
BUILD_DIR=./build
if [ ! -d ${EXE_DIR} ]
then
mkdir ${EXE_DIR}
else
#echo "aaa"
rm -rf ${EXE_DIR}/*
fi
if [ ! -d ${BUILD_DIR} ]
then
mkdir ${BUILD_DIR}
else
#echo "ccc"
rm -rf ${BUILD_DIR}/*
fi
cd build
cmake ..
make
cmake 参考
https://github.com/doctording/cmake_study
执行运行
$./travis.sh