Makefile1

我的第一个Makefile

all: main.o hello.o function.o
	gcc -o main $^
main.o : main.c function.o hello.o
	gcc -c main.c -I ./include -I ./src
hello.o :  src/hello.c 
	gcc -c ./src/hello.c -I ./include
  
function.o : src/function.c 
	gcc -c ./src/function.c -I ./include 

clean:
	rm -rf *.omZ

出现的问题:

1,在Makefile脚本中,在指令前必须有一个tab,但是用MobaText的tab与Linux识别的tab,不一样。所以切换为vim重新编辑。其实问题也切换之后才发现的

2, 在编译原文件,所依赖项 .h 不能加,不知道为什么

另外以下几种都是错误的写法:

hello.o :  ./src/hello.c 

hello.o :  hello.c 

hello.o : hello.c hello.h

猜你喜欢

转载自blog.csdn.net/qq_24328911/article/details/83215527
今日推荐