|
实例一:
头文件 head.h
#define MAXSIZE 128
int test_func1 (int);
int test_func2 (int, int);
fun1.c 文件:#include "head.h"
int test_func1 (int num)
{
int fun1;
fun1 = num + MAXSIZE;
return fun1;
}
fun2.c 文件:
#include "head.h"
int test_func2(int a, int b)
{
int new;
new = a + b + MAXSIZE;
return new;
}
Makefile 文件:
hello.exe:fun1.o fun2.o hello.o
gcc fun1.o fun2.o hello.o -o hello.exe
hello.o:hello.c fun1.o fun2.o
gcc -Wall -g -c hello.c -o hello.o
fun1.o: fun1.c head.h
gcc -Wall -g -c fun1.c -o fun1.o
fun2.o: fun2.c head.h
gcc -Wall -g -c fun2.c -o fun2.o
make 运行结果:beyes@linux-beyes:~/C/Make> make
gcc -Wall -g -c fun1.c -o fun1.o
gcc -Wall -g -c fun2.c -o fun2.o
gcc -Wall -g -c hello.c -o hello.o
gcc fun1.o fun2.o hello.o -o hello.exe
注意:
如果在头文件 head.h 中没有对 fun1.c 和 fun2.c 两个文件中的函数进行声明,那么就会输出警告信息:hello.c:10: warning: implicit declaration of function ‘test_func1’
hello.c:12: warning: implicit declaration of function ‘test_func2’ |
|