1、编写一个简单的程序(main.cpp)
//创建一个工程目录,进入其中创建main.cpp
touch main.cpp //用vscode或者文本编写以下程序
#include <iostream>
using namespace std;
int main()
{
cout<<"hello cmake"<<endl;
return 0;
}
2、编写CMakeLists.txt文件,并将其与main.cpp放在同一个目录下
project(hello) //hello是工程目录的名字
add_executable(hello main.cpp)
3、进入CMakeLists.txt所在目录,在CMakeLists.txt 所在的目录下创建一个 build目录,进入build目录在终端输入:
cmake ..
make
4、在build文件中生成可执行文件
./hello //hello是可执行文件的名字