目录
01.创建Cmake文件夹
内部包含HelloWorld.cpp、CMakeLists.txt。
HelloWorld.cpp:
#include <iostream>
using namespace std;
int main() {
cout<<"HelloWorld"<<endl;
system("pause");
return 0;
}
CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (HelloWorld)
add_executable (HelloWorld HelloWorld.cpp)
02.生成编译工程文件
进入cmake文件夹目录,运行命令
cmake .
03.编译工程
运行命令(注:默认是Debug模式)
cmake --build .
若要运行Release模式,换成以下命令
cmake --build . -- /p:Configuration=Release
04.运行程序
进入到带有exe的目录(在Debug或Release文件夹下)
cd Debug //或者是 cd Release
执行HelloWorld.exe
HelloWorld.exe
输出结果: