1.Linux系统下第一个cmake项目
Cmake
1.安装工具
1 | #更新apt |
验证工具是否安装
1 | # 以下命令确认每个软件是否安装成功 |
2.编写C++代码
创建项目文件夹
1
mkdir hello
在当前目录创建文件
main.cpp1
touch main.cpp
编写代码
1
2
3
4
5
6//main.cpp
int main(){
printf("hello,world!");
return 0;
}
3.编写文件CmakeLists.txt
在当前目录创建文件
CmakeLists.txt1
touch CmakeLists.txt
编写内容
1
2
3
4
5
6
7cmake_minimum_required(VERSION 3.10)
#project name
PROJECT(hello)
#add executable file
ADD_EXECUTABLE(hello main.c)创建构建目录
1
2
3
4
5
6
7
8mkdir build
## 4.编译cmake项目
4. 进入到构建目录
```sh
cd build使用
cmake命令生成生成相关配置1
2
3
4
5
6cmake ..
6. 使用make命令编译程序
```sh
make
5. 运行程序
1 | ./hello |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
