Environment Setting Project address
Https://github.com/open-source-parsers/jsoncpp.git
Operating system
64位 Fedora 24
Installing 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_profilePKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfigexport PKG_CONFIG_PATHLD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH$ source ~/.bash_profile### 生成帮助文档,web文档的index.html在当前目录%DOC_TOPDIR%/%HTML_OUTPUT%下$ sudo yum install -y doxygen$ doxygen web_doxyfile.in
Project catalog structure (template)
$ lsCMakeLists.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})#dependenciesINCLUDE(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})
Compiling a Run project (template)
$ mkdir build$ cd build$ cmake ..$ make$ ./sample
Jsoncpp Development Environment Construction