1. Create a new folder and main.cpp file
#include <iostream>
using namespace std;
int main() {
std::cout << "hello world" << std::endl;
system("pause");
return 0;
}
2. Write the CMakeLists.txt file
PROJECT (HELLO)
SET(SRC_LIST main.cpp)
MESSAGE(STATUS "THIS IS BINARY DIR " ${HELLO_BINARY_DIR})
MESSAGE(STATUS "THIS IS SOURCE DIR " ${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ${SRC_LIST})
The meaning of the content can be found in other articles.
3. Then according to the tutorial, you should enter cmake . to generate the makefile.
3.1 The compiler defaults to vs under windows, which will generate a lot of files.
Problem: cmake does not generate makefiles under windows.
3.2 No longer continue here, delete, and then only mian.cpp and CMakeLists.txt are left. Re-enter cmake -S ./ -B ./ -G "MinGW Makefiles". (Of course, you need to have MinGW on your computer and configure environment variables here)
You can see that the makefile is generated.
3.3 Then enter make in cmd.
The problem occurs , 'make' is not recognized as an internal or external command, operable program
Solution: Find mingw32-make.exe. You can make a copy and rename it to make.exe.
continue. make in cmd.
You can see that hello.exe has been generated
3.4 run hello.exe