CMAKE 编译项目流程

1、安装 cmake

sudo snap install cmake  # version 3.30.0, 
or
sudo apt  install cmake  # version 3.27.8-1build1

2、创建 CMakeLists.txt 文件

projet/
├── src/
│   └── chrono.cpp
└── CMakeLists.txt

3、编写 CMakeLists.txt 文件

cmake_minimum_required(VERSION 3.10)
project(aap_platform)

# 设置 vcpkg 路径
set(CMAKE_TOOLCHAIN_FILE /opt/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")

# 指定 C++ 标准
set(CMAKE_CXX_STANDARD 17)

# 添加可执行文件
add_executable(aap_platform src/chrono.cpp)

# 链接 stduuid 库
find_package(stduuid CONFIG REQUIRED)
target_link_libraries(aap_platform PRIVATE stduuid)

3、在项目根目录下运行 CMake 以生成构建文件,然后编译项目

mkdir build
cd build
cmake ..
cd ..
cmake --build build -j

4、如果编译文件出现 找不到文件

CMake Error at CMakeLists.txt:14 (find_package):
  Could not find a package configuration file provided by "stduuid" with any
  of the following names:

    stduuidConfig.cmake
    stduuid-config.cmake

  Add the installation prefix of "stduuid" to CMAKE_PREFIX_PATH or set
  "stduuid_DIR" to a directory containing one of the above files.  If
  "stduuid" provides a separate development package or SDK, be sure it has
  been installed.

可以进行尝试手动添加文件所在位置 (例如如下)  

cmake -Dstduuid_DIR=/opt/vcpkg/installed/x64-linux/share/stduuid ..

5、下面就可以进行编译运行文件

# 在项目(如 project)下

cmake --build build -j
./build/aap_platform

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值