一、安裝Cmakeios
二、安裝MinGWwindows
三、配置環境變量ui
D:\CMake\bin;D:\mingw\bin
四、將MinGW目錄\bin下的mingw32-make.exe重命名爲make.exespa
五、建立目錄 hello.net
六、建立文件 hello.cppcode
#include <iostream> using namespace std; int main() { cout<<"Hello World"<<endl; return 0; }
七、建立文件 CMakeLists.txtblog
#設置C編譯器 set(CMAKE_C_FLAGS "-g -Wall -I D:\\mingw\\include -L D:\\mingw\\lib")# set(CMAKE_CXX_COMPILER "g++")#設置C++編譯器 set(CMAKE_CXX_FLAGS "-g -Wall -I D:\\mingw\\include -L D:\\mingw\\lib") PROJECT (HELLO CXX) SET(SRC_LIST hello.cpp) ADD_EXECUTABLE(hello ${SRC_LIST}) MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR}) MESSAGE(STATUS "This is SOURCE dir " ${HELLO_SOURCE_DIR})
八、執行命令編譯器
cd hello cmake -G "MinGW Makefiles" . make
九、運行程序it
hello
錯誤io
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. 在命令中指定路徑 cmake -G "MinGW Makefiles" -D"CMAKE_MAKE_PROGRAM:PATH=D:/work/program/Qt/Qt5.6.2/Tools/mingw492_32/bin/make.exe" .
參考
windows下使用cmake+mingw配置makefile http://blog.csdn.net/xiaopangzi313/article/details/53115702 CMake 入門實戰 http://www.hahack.com/codes/cmake/ cmake使用示例與整理總結 http://blog.csdn.net/wzzfeitian/article/details/40963457/