makefile和make
管理工程 实现自动化编译 (和 vs 比较)示例: 对 main.c add.c max.c 三个文件进行编译(注意: gcc 前面必须是 table键缩进) 1.编写makefile文件
wys@DESKTOP-2OU3HRV:~/mycode/day02$ vim makefile
1 all : main
2
3 main: main.o add.o max.o
4 gcc -o main main.o add.o max.o
5
6 main.o: main.c
7 gcc -c main.c
8
9 add.o : add.c
10 gcc -c add.c
11
12 max.o : max.c
13 gcc -c max.c
14
15 clean:
16 rm -f *.o main
17
wys@DESKTOP-2OU3HRV:~/mycode/day02$ ls
add.c add.h main.c makefile max.c max.h
wys@DESKTOP-2OU3HRV:~/mycode/day02$
2.make 命令根据 makefile 文件的规则生成可执行程序
wys@DESKTOP-2OU3HRV:~/mycode/day02$ ls
add.c add.h main.c makefile max.c max.h
wys@DESKTOP-2OU3HRV:~/mycode/day02$ make
gcc -c main.c
gcc -c add.c
gcc -c max.c
gcc -o main main.o add.o max.o
wys@DESKTOP-2OU3HRV:~/mycode/day02$ ls
add.c add.h add.o main main.c main.o makefile max.c max.h max.o
wys@DESKTOP-2OU3HRV:~/mycode/day02$ ./main
a + b=5
max=5
wys@DESKTOP-2OU3HRV:~/mycode/day02$
|