Makefile介绍
make(GNU make)项目构建工具,是自动编译管理器,根据文件时间戳,自动发现更新过的文件,减少编译的工作量。管理哪个文件改动之后需要重新编译,如何编译。
make会读入Makefile文件的内容执行大量的编译工作。提高的项目开发和维护的工作效率。
Makefile,规则文件,告诉make如何进行编译和管理。
Makefile环境安装
Linux
sudo apt install gcc g++ make
make --version
Window
推荐使用w64devkit套件
官网:https://www.mingw-w64.org
下载地址:https://github.com/skeeto/w64devkit/releases
下载电脑对应版本,解压,将bin的文件路径添加到系统环境变量中。
学习资料
make官方文档:https://www.gnu.org/software/make/manual/make.html
2048: https://github.com/plibither8/2048.cpp
sudoku:https://github.com/mayerui/sudoku
Makefile基本结构
1、工具创建的目标体(target),目标文件,可执行文件
2、目标体的依赖文件(dependency_file)
3、创建目标体需要的运行命令(command)
target:dependency_files
command
比如有两个文件,hello.c
和hello.h
,创建目标是hello.o
hello.o: hello.c hello.h
gcc -c hello.c -o hello.o
Makefile在每一个command前必须有"Tab"符,不然在运行make命令时会出错。
接下来运行make命令就可以了。