使用cmake编译和安装jsoncpp-0.10.2

简介: 网上主要介绍了python方式编译安装jsoncpp,但它的官网有介绍cmake安装命令行安装方式,以下笔记在SUSE Linux g++ 4.1.0上经过验证。 使用cmake生成Makefile文件,类似于执行automake的“configure”:cmake -DBUILD...
网上主要介绍了python方式编译安装jsoncpp,但它的官网有介绍cmake安装命令行安装方式,以下笔记在SUSE Linux g++ 4.1.0上经过验证。


使用cmake生成Makefile文件,类似于执行automake的“configure”:
cmake -DBUILD_ STATIC_LIBS=ON -DBUILD_ SHARED_LIBS=OFF -D INCLUDE _INSTALL_DIR=/usr/local/thirdparty/jsoncpp-0.10.2/include -D ARCHIVE _INSTALL_DIR=/usr/local/thirdparty/jsoncpp-0.10.2/lib


这一步成功后,可以看到产生了Makefile文件,之后就可以执行“make”编译和“make install“安装了。


“cmake”参数说明:
INCLUDE_INSTALL_DIR为指定“头文件”的安装目录
ARCHIVE_INSTALL_DIR为指定“静态库文件”的安装目录
LIBRARY_INSTALL_DIR为指定“共享库文件”的安装目录
RUNTIME_INSTALL_DIR为指定“可执行程序文件”的安装目录


BUILD_STATIC_LIBS=ON 表示生成静态库文件
BUILD_SHARED_LIBS=OFF 表示不生成共享库文件


如果想编译成debug版本,则加上“-DCMAKE_BUILD_TYPE=debug”。


遇到的编译错误1:
include/json/config.h:100: error: ISO C++ does not support 'long long'
include/json/config.h:101: error: ISO C++ does not support 'long long'


解决方法:
修改include/json/config.h,将下面一段
#if defined(_MSC_VER) // Microsoft Visual Studio
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else                 // if defined(_MSC_VER) // Other platforms, use long long
typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif // if defined(_MSC_VER)


修改成:
#if defined(_MSC_VER) // Microsoft Visual Studio
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else                 // if defined(_MSC_VER) // Other platforms, use long long
__extension__ typedef long long int Int64;
__extension__ typedef unsigned long long int UInt64;
#endif // if defined(_MSC_VER)


注意要加“__extension__”修饰,因为“long long”是C99标准中的,“ __extension__”表示启用g++的扩展。


遇到的编译错误2:
/tmp/X/jsoncpp-0.10.2/src/test_lib_json/main.cpp:1243: error: integer constant is too large for 'long' type


解决方法:
测试代码,可直接注释掉1243一行代码。

jsoncpp下载网址: https://github.com/open-source-parsers/jsoncpp/releases


附:cmake编译安装
如果机器上没有cmake,则需要先安装它。
将cmake源代码包上传到Linux机器,解压它,然后执行“./configure --prefix=INSTALL_DIRECTORY”,
比如:./configure --prefix=/usr/local/cmake-3.2.2。
“configure”实际是调用了同目录下的“bootstrap.sh”。

接着就可以执行“make”编译,编译成功后再执行“make install”安装。

目录
打赏
0
0
0
0
9
分享
相关文章
CMake基础(3)静态库
CMake基础(3)静态库
99 1
|
10月前
CMake基础(4)动态库
CMake基础(4)动态库
100 1
cmake+vs2019编译OpenCV
cmake+vs2019编译OpenCV
111 0
|
9月前
我为什么更推荐你使用cmake编译grpc程序?
我为什么更推荐你使用cmake编译grpc程序?
178 0
linux下configure,make(makefile),cmake命令详解-makefile和CMakeList
linux下configure,make(makefile),cmake命令详解-makefile和CMakeList
CMake基础(9)使用Clang编译
CMake基础(9)使用Clang编译
714 0
zlib-1.2.11库、libpng-1.6.36库编译及交叉编译 —— 附带shell编译脚本及源码
zlib-1.2.11库、libpng-1.6.36库编译及交叉编译 —— 附带shell编译脚本及源码
739 0
zlib-1.2.11库、libpng-1.6.36库编译及交叉编译 —— 附带shell编译脚本及源码
cmake安装与使用
cmake安装与使用
385 0
cmake安装与使用
cmake编译问题解决
<p><br></p> <p></p> <p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px"> <strong>2 安装cmake软件包</strong><br> yu
30959 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等