我正在尝试创建一个makefile,这样我就可以编译多个C文件。这个makefile没有按预期工作,只在我运行make all
时编译ex1并给出关于ex3的错误(参见错误日志)
CFLAGS=-Wall -g
all:
make ex1
make ex3
clean:
rm -f ex1
rm -f ex3
错误:
make all
make ex1
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
cc -Wall -g ex1.c -o ex1
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make ex3
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make[1]: *** No rule to make target 'ex3'. Stop.
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
答案 0 :(得分:1)
以递归方式调用make
是一个坏主意。您应该按如下方式编写makefile:
CFLAGS=-Wall -g
all: ex1 ex3
clean:
rm -f ex1 ex3