文章目录
前言
本文所写代码是基于linux下的编程
一、文件
a.c
#include <stdio.h>
#include "a.h"
int main()
{
printf("hello, world!\n");
printf("A= %d\n", A);
test_fun();
return 0;
}
b.c
#include <stdio.h>
#include "a.h"
int test_fun()
{
printf("it is B\n");
return 0;
}
a.h
#define A 1
int test_fun();
二、makefile的升级
上一个引入的makefile缺点很多,需要进行修改:
makefile
test:a.o b.o
gcc -o test a.o b.o
a.o : a.c
gcc -c -o a.o a.c
b.o : b.c
gcc -c -o b.o b.c
-c: 表示只进行预处理,编译,汇编,但不进行链接
这样子做的好处:
我们如果只修改其中一个文件,他只会去预处理,编译,汇编我们修改的文件,不会把全部文件都再做一遍,这样子效率就变高了。
修改a.c后.他只进a.c的预处理,编译,汇编,b.c没有修改不会在进行预处理,编译,汇编。
缺点:
如果有很多个文件,那么makefile中是不是要写上千万条
a.o : a.c gcc -c -o a.o a.c
同时如果我修改a.h整体不会产生变化,不会进行新的编译结果。