编程语言
首页 > 编程语言> > c++ 三方库的构建与安装

c++ 三方库的构建与安装

作者:互联网

cmake

gnu 套件不含 cmake, 通常需要 apt-get 自行安装.
cmake 用来跨平台, 灵活的生成 makefile.
通常项目根目录(记为 target_dir)中有 CMakeLists.txt, cmake ${target_dir} 即可搜寻目录下的 CMakeLists.txt , 生成 makefile. 执行过程中会有各种中间文件产生, 为了不污染项目, 通常一串操作为

mkdir build
cd build
cmake ..

注意 cmake 后的参数只能为目录, 不能为文件.
在这里插入图片描述
图:cmake 命令后的执行过程, 生成 Makefile

make

接上步得到的 Makefile, 可以执行不同的 命令.
在这里插入图片描述

install

执行 install, 就会安装 include 与 lib了.
在这里插入图片描述
图: 来自 nlohmann/json 三方库的安装, 它是 header_only 的, 所以lib中放的是cmake, 等价于没放吧.

header_only library

为了可读性, 便于移植? 一个头文件已经包含了所有的实现, 就不再需要 .lib 库文件了.
nlohmann/json.hpp 中, 源码有2.2万行.

标签:三方,CMakeLists,cmake,lib,Makefile,c++,header,构建,安装
来源: https://blog.csdn.net/chuchus/article/details/122779358