【发布时间】:2019-02-06 04:11:21
【问题描述】:
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。
对于我的一个项目,我有一个 makefile 如下:
CC=g++
CFLAGS=-O3 `libpng-config --cflags`
LFLAGS=-lm `libpng-config --ldflags`
OBJS=basic_render.o render.o mandel.o
BINS=basic_render
.PHONY: all clean
all: $(BINS)
clean:
rm -f $(BINS) $(OBJS)
%.o: %.cpp
$(CC) $(CFLAGS) -c -o $@ $<
%: $(OBJS)
$(CC) $(LFLAGS) -o $@ $(OBJS)
在构建时,我希望能够简单地运行
make clean
make
构建 BINS 列表中的所有内容。
起初这很好用,但由于某种原因,在我编辑源文件后行为发生了变化。
编辑源文件之前:
$ make clean
rm -f basic_render basic_render.o render.o mandel.o
$ make
g++ -O3 `libpng-config --cflags` -c -o basic_render.o basic_render.cpp
g++ -O3 `libpng-config --cflags` -c -o render.o render.cpp
g++ -O3 `libpng-config --cflags` -c -o mandel.o mandel.cpp
g++ -lm `libpng-config --ldflags` -o basic_render basic_render.o render.o mandel.o
rm mandel.o basic_render.o render.o
我可以一遍又一遍地这样做,而且效果很好。在我对basic_render.cpp 进行更改(实际上只是更改了几个常量)之后,它突然变成了这样:
$ make clean
g++ -O3 `libpng-config --cflags` -c -o basic_render.o basic_render.cpp
g++ -O3 `libpng-config --cflags` -c -o render.o render.cpp
g++ -O3 `libpng-config --cflags` -c -o mandel.o mandel.cpp
g++ -lm `libpng-config --ldflags` -o makefile basic_render.o render.o mandel.o
rm mandel.o basic_render.o render.o
makefile:1: warning: NUL character seen; rest of line ignored
makefile:1: *** missing separator. Stop.
make clean 不仅只是尝试编译程序,它还编译了basic_render,并在Makefile 中设置了输出,覆盖了Makefile 本身。
编辑basic_render.cpp后,我查看了Makefile,它并没有改变,所以我的编辑器不是在改变makefile什么的。
那么,我在这里做错了什么?
【问题讨论】: