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