假设应用程序源程序有三个文件main.c,printf.c,printf.h,生成执行文件为helloworld
假如main.c,printf.c,printf.h与makefile在同一目录,则makefile可以如下编写:
helloworld : main.o printf.o
gcc -o helloworld main.o printf.o
main.o : main.c
gcc -c main.c
printf.o : printf.c
gcc -c printf.c
clean:
rm main.o printf.o helloworld
假如main.c,printf.c与makefile在同一目录,而printf.h在当前目录的/include下,则makefile可如下编写:
helloworld : main.o printf.o
gcc -o helloworld main.o printf.o
CFLAGS := -I$(shell pwd)/include
main.o : main.c
gcc -c main.c $(CFLAGS)
printf.o : printf.c
gcc -c printf.c $(CFLAGS)
clean:
rm main.o printf.o helloworld