GNU make 在 makefile 完成之前停止而没有错误

Posted

技术标签:

【中文标题】GNU make 在 makefile 完成之前停止而没有错误【英文标题】:GNU make stops without error before makefile is finished 【发布时间】:2017-03-17 23:37:32 【问题描述】:

早上好, 我正在尝试在 Windows 7 下使用 Eclipse 和 GNU-Arm 工具链交叉编译 Atmel AT92SAM。

我的问题是,链接器完成后构建过程停止,尽管它还应该创建一个原始二进制文件并打印大小。 这是 eclipse 创建的 makefile 的摘录:

# All Target
all: main.exe

# Tool invocations
main.exe: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: Cross ARM C Linker'
    arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb -O0 -fsigned-char -ffunction-sections  -g -Xlinker --gc-sections -Wl,-Map,"main.map" --entry=0x00000000 -o "main.exe" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

main.bin: main.exe
    @echo 'Invoking: Cross ARM GNU Create Flash Image'
    arm-none-eabi-objcopy -O binary "main.exe"  "main.bin"
    @echo 'Finished building: $@'
    @echo ' '

main.siz: main.exe
    @echo 'Invoking: Cross ARM GNU Print Size'
    arm-none-eabi-size --format=berkeley "main.exe"
    @echo 'Finished building: $@'
    @echo ' '

但是最后两个命令没有执行,也没有创建 .bin。命令行输出是

...
Finished building: ../src/main.c

Building file: ../.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.c
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb -O0 -fsigned-char -ffunction-sections  -g -DTRACE_LEVEL=4 -Dflash -Dat91sam7x512  -I"[My includes] -std=gnu99 -MMD -MP -MF".metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.d" -MT".metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.o" -c -o ".metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.o" "../.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.c"
Finished building: ../.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.c

Building file: ../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb -O0 -fsigned-char -ffunction-sections  -g -DTRACE_LEVEL=4 -Dflash -Dat91sam7x512 -I"[my includes]" -std=gnu99 -MMD -MP -MF".metadata/.plugins/org.eclipse.cdt.make.core/specs.d" -MT".metadata/.plugins/org.eclipse.cdt.make.core/specs.o" -c -o ".metadata/.plugins/org.eclipse.cdt.make.core/specs.o" "../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c"
Finished building: ../.metadata/.plugins/org.eclipse.cdt.make.core/specs.c

Building target: main.exe
Invoking: Cross ARM C Linker
arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb -O0 -fsigned-char -ffunction-sections  -g -Xlinker --gc-sections -Wl,-Map,"main.map" --entry=0x00000000 -o "main.exe"  [my object files]  ./.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.o  ./.metadata/.plugins/org.eclipse.cdt.make.core/specs.o   -lm
Finished building target: main.exe


08:31:22 Build Finished (took 10s.91ms)

如您所见,没有调用 objcopy 和 size 命令。 有什么想法吗?

【问题讨论】:

您是在调用“make”还是“make all”?如果是这样,它正在做你的“全部”目标告诉它...... all: main.bin main.siz 你是对的..显然eclipse选项设置不正确。 【参考方案1】:

您可以直接在main.exe 配方中添加大小,因为main.siz 不是真正的输出文件(应该是.PHONY):

all: main.bin

main.exe: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: Cross ARM C Linker'
    arm-none-eabi-gcc -mcpu=arm7tdmi -mthumb -O0 -fsigned-char -ffunction-sections  -g -Xlinker --gc-sections -Wl,-Map,"main.map" --entry=0x00000000 -o "$@" $(OBJS) $(USER_OBJS) $(LIBS)
    arm-none-eabi-size --format=berkeley "$@"
    @echo 'Finished building target: $@'

main.bin: main.exe
    @echo 'Invoking: Cross ARM GNU Create Flash Image'
    arm-none-eabi-objcopy -O binary "$<" "$@"
    @echo 'Finished building: $@'

【讨论】:

以上是关于GNU make 在 makefile 完成之前停止而没有错误的主要内容,如果未能解决你的问题,请参考以下文章

GNU make简要介绍①

让 GNU Make 和 NMake 默认使用不同的 makefile

使用GNU make,嵌入式C进行本机和交叉编译

《GNU_makefile》第五章——为规则书写命令

《GNU_makefile》第五章——为规则书写命令

编译时如何更改 makefile 诊断消息 [GNU ARM GCC, Eclipse make.exe]