为什么同一个 CFLAGS 可以在 makefile 中重复两次?

Why the same CFLAGS can be repeated twice in a makefile?

这是 makefile 的部分:

CFLAGS += -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16

CFLAGS  = -g -O2 -Wall
CFLAGS += -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16

第一行和第三行完全一样

第一行注释后,"make"不会出错。

但是在注释第三行之后,"make"就出错了。 错误:

/tmp/ccIrbEv9.s: Assembler messages:
/tmp/ccIrbEv9.s:77: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:368: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:402: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:1276: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:1305: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:1371: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:1400: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:1544: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:1573: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:1643: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:1672: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:2989: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3021: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3060: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3096: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3342: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3371: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:3443: Error: selected processor does not support `rbit r0,r0' in ARM mode
/tmp/ccIrbEv9.s:3472: Error: selected processor does not support `rbit r0,r3' in ARM mode
/tmp/ccIrbEv9.s:3783: Error: selected processor does not support `rbit r0,r0' in ARM mode
Makefile:27: recipe for target 'Src/stm32f7xx_hal_dma2d.o' failed 

我感到很困惑。

CFLAGS = -g -O2 -Wall

此行会覆盖第一行(注意分配),因此,如果您删除第三行,您将在没有这些选项的情况下进行编译,并且会应用工具链默认值。 在这种非常特殊的情况下,编译器似乎不接受默认目标的来源。

注意区别

CFLAGS += ...

和:

CFLAGS = ...

加号让一切变得不同。它通过附加标志修改 CFLAGS 值。没有加号,值被替换,之前的值丢失。

  1. 第一个CFLAGS += ...可以去掉,因为它的值被CFLAGS = ...代替了。

  2. CFLAGS = ... 可以删除,因为代码在没有它们的情况下也能编译。

  3. 不能删除最后一个 CFLAGS += ...,因为它提供了对您的代码必不可少的编译器标志。