所需文件hello.c, main.c, hello.h, Makefile,在同一个目录下
hello.c:
#include <stdio.h> void hello(char name[]) { printf("Hello %s!/n", name); }
main.c:
#include "stdio.h" #include "hello.h" // The second int main() { hello("GCC"); printf("Haha Linux Ubuntu!/n"); return 0; }
hello.h:
void hello(char name[]);
Makefile(之所以用大写,因为make可以识别Makefile和makefile,用大写可以鲜明一些):
# String declaration objects = main.o hello.o # Command app : $(objects) cc -o app main.o hello.o main.o : main.c hello.h cc -c main.c hello.o : hello.c stdio.h cc -c hello.c # Search paths vpath %.h /usr/include # Clean the intermediate files .PHONY : clean clean : rm app $(objects)