环境设置
项目地址
https://github.com/open-source-parsers/jsoncpp.git
操作系统
64位 Fedora 24
安装jsoncpp
$ git clone https://github.com/open-source-parsers/jsoncpp.git
$ cd jsoncpp/
$ mkdir -p build/debug
$ cd build/debug
$ cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF ../..
$ make
$ sudo make install
### 设置pkg-config查找路径
$ tail -n 8 .bash_profile
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
$ source ~/.bash_profile
### 生成帮助文档,web文档的index.html在当前目录%DOC_TOPDIR%/%HTML_OUTPUT%下
$ sudo yum install -y doxygen
$ doxygen web_doxyfile.in
工程目录结构(模板)
$ ls
CMakeLists.txt main.cpp
$ cat CMakeLists.txt
#cmake的最低版本
cmake_minimum_required(VERSION 2.8)
#工程名
project(jsoncpp)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
#遍历当前目录及子目录获取所有源文件
file(GLOB SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
#设置源文件列表
add_executable(sample ${SRC})
#dependencies
INCLUDE(FindPkgConfig)
#使用pkg-config寻找protobuf库的include目录以及库
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
include_directories(${JSONCPP_INCLUDE_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
#设置链接库
target_link_libraries(sample ${JSONCPP_LIBRARIES})
编译运行项目(模板)
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./sample