为什么要“制作”?总是重建目标?
我的 Makefile 是:
OBJS = b.o c.o a.o
FLAGS = -Wall -Werror
CC = gcc
test: $(OBJS)
$(CC) $(FLAGS) $(OBJS) -o test
b.o: b.c b.h
$(CC) $(FLAGS) -c b.c
a.o: a.c b.h c.h
$(CC) $(FLAGS) -c a.c
c.o: c.c c.h
$(CC) $(FLAGS) -c c.c
clean:
rm a
rm *.o
all: test
如果我再次执行 make
,然后再次执行 make
,它总是会重建“test”。为什么要这样做?
即使我这样做:make ao
它也会重建...如果有帮助的话,我在linux上。
在 Windows 中,如果我将“test”更改为“test.exe”,将“-o test”更改为“-o test.exe”,则效果很好。 所以我猜由于某种原因,我的 Linux 中的“make”无法检查目录中文件的日期戳。
我修好了! .c 是在 Windows 中创建的。我在 vi 中打开了所有 .c 和 .h,并且没有执行任何操作保存更改,并且一切正常。我认为日期戳的事情已经解决了。
My Makefile is:
OBJS = b.o c.o a.o
FLAGS = -Wall -Werror
CC = gcc
test: $(OBJS)
$(CC) $(FLAGS) $(OBJS) -o test
b.o: b.c b.h
$(CC) $(FLAGS) -c b.c
a.o: a.c b.h c.h
$(CC) $(FLAGS) -c a.c
c.o: c.c c.h
$(CC) $(FLAGS) -c c.c
clean:
rm a
rm *.o
all: test
If I do make
then make
again, it always rebuilds 'test'. Why does it do this?
Even if i do: make a.o
it rebuilds... Im on linux if that helps.
In windows if I change 'test' by 'test.exe' and '-o test' by '-o test.exe', it works fine.
So I guess that for some reason 'make' in my linux cant check the datestamps of my files in the directory.
I FIXED IT!
The .c were created in Windows. I opened all .c and .h in vi, and without doing nothing save changes, and all worked. I think that the datestamp thing was fixed doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的第一条规则是:
这意味着如果名为“test”的文件不存在,则应运行该规则并创建它。由于“test”永远不存在(该规则实际上不会创建名为“test”的文件),因此它每次都会运行。您应该将“test”更改为“a”,即该规则的实际输出
为了将来参考,如果规则实际上并未在左侧创建内容,则应该将其标记为:
Your first rule is:
That means if a file named 'test' doesn't exist, the rule should run and create it. Since 'test' never exists (that rule doesn't actually create a file named 'test'), it runs every time. You should change 'test' to 'a', the actual output of that rule
For future reference, if a rule doesn't actually create the thing on the left-hand side, you should mark it with:
作为最后的手段,您可以在调试模式下运行 Make (make -d) 并梳理输出。在尝试之前,我建议您在“测试”规则中添加一行,看看是否存在 Make 认为需要重建测试的先决条件(并在编译命令中使用一些自动变量,作为一个很好的做法)。
As a last resort you can run Make in debug mode (make -d) and comb through the output. Before trying that, I suggest you add a line to the "test" rule to see if there are any prerequisites that Make thinks require the rebuilding of test (and use some automatic variables in the compile command, as a good practice).
您需要指定 test 是 phony target:
我将all放在第一位,因此它是默认目标(这是常见的),删除了编译命令(make已经内置了这些命令),并更改了FLAGS 到 CFLAGS (这是 C 编译器标志的通用名称,由 make 的内置规则使用)。
You need to specify that test is a phony target:
I've placed all first so it is the default target (which is common), removed the commands for compiling (make already has those built-in), and changed FLAGS to CFLAGS (which is the common name for C compiler flags and used by make's built-in rules).