Before reading this article, please confirm that you understand
Http://blog.csdn.net/dcmilan/article/details/7983697
Http://blog.csdn.net/dcmilan/article/details/7986961
1. Install msys
Msys can be downloaded from the mingw official website. I will use version 1.0 here.
After installation, the GNU make file is displayed in the C: \ msys \ 1.0 \ bin folder.
When using make in cmd, You need to display the call full path C: \ msys \ 1.0 \ bin \ Make
2. Prepare CPP and makefile
// hello.cpp#include <iostream>int main( ){ std::cout << "Hello, World!\n";}
// Makefile (this line should not appear in the Code. The command line part of makefile must start with a tab rather than a space) # This is the default target, which will be built when # You invoke make. phony: allall: hello # This rule tells make how to build hello From hello. cpphello: Hello. cppg ++-O hello. CPP # This rule tells make to copy hello to the binaries subdirectory, # creating it if necessary. phony: installinstall: C:/msys/1.0/bin/mkdir-P binariesc:/msys/1.0/bin/CP Hello binaries # This rule tells make to delete hello and hello. o. phony: cleanclean: C:/msys/1.0/bin/Rm-F hello
Create a folder "hello", and then create the corresponding file "Hello. cpp" and "makefile" in the "hello" folder.
3. Execute the make command
Switch the directory to hello in the CMD environment.
Run the C:/msys/1.0/bin/make Hello command.
Generate hello.exe
Then run C:/msys/1.0/bin/make install.
Create a binariesfolder and copy hello.exe to it
Note: The makefile here is the complete file name. Make command
The file is automatically located and the corresponding segment of the file is operated.