一、C++代码示例
//first_cmake.cpp
#include<iostream>
using namespace std;
int main(int argc ,char *argv[])
{
cout<<"hello camke!"<<endl;
return 0;
}
二、CMakeLists.txt编写
#CMakeLists.txt cmake文件名大小写不敏感
#指定cmake最低版本
cmake_minimum_required(VERSION 3.20)
#构建项目的名称
project(first_cmake)
#构建执行程序
add_executable(first_cmake first_cmake.cpp)
三、文件结构
四、编译
1.cmake编译: cmake .
2.Debug编译:cmake --build .
3.指定路径编译
新建build文件夹
cmake ..
cmake --build .
cmake -S . -B b
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/VsFMs