什么是" thing.o中的隐含命令:thing.c"在Makefile中?

时间:2016-05-11 12:21:45

标签: c makefile

我有一行Makefile:

thing.o: thing.c

我想给出一个明确的命令来做同样的事情,因为我需要修改运行的内容。

隐含的命令是什么?

如果我尝试:

$(CC) $(CFLAGS) thing.c -o thing.o

我收到错误,所以我认为这不是隐含的。

当我使用隐式make规则(即我指定no命令)时,它可以正常工作。

(仅当明确指定命令时,错误是:

/opt/avr8-gnu-toolchain-linux_x86_64/bin/avr-gcc -g -Wall -mcall-prologues -mmcu=atmega328p  -Os thing.o -Wl,-gc-sections -Wl,-relax -o pmu.obj
pmu.o: In function `__vector_22':
(.text+0x7c): multiple definition of `__bad_interrupt'
/opt/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.text+0x0): first defined here
/opt/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
thing.o: In function `__vectors':
(.text+0x0): multiple definition of `__vectors'
/opt/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.vectors+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [thing.obj] Error 1

但确切的错误并不重要 - 我需要找到我可以替换隐式命令的内容。)

2 个答案:

答案 0 :(得分:1)

它只是编译(不是链接),因此你需要选项-c:

$(CC) $(CFLAGS) -c thing.c

答案 1 :(得分:1)

您可以使用make -pn转储内置规则,您正在寻找的规则是

%.o: %.c
    $(COMPILE.c) $(OUTPUT_OPTION) $<

可以进一步细分为

$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
{p> -c可能是罪魁祸首,尽管CPPFLAGS也可能发挥作用。

相关问题