【问题标题】:How can I catch a command error and continue the compilation in a makefile?如何捕获命令错误并在生成文件中继续编译?
【发布时间】:2017-11-04 08:45:22
【问题描述】:

例如,在编译过程中会产生错误 L6220E(由于我使用的是 ARM 编译器,此错误标志表示内部闪存内存不足)。我想要做的是即使生成了错误也继续编译。有什么方法可以捕获命令错误并运行其他命令?喜欢,

normal_target:
             gcc -o main main.c    (this will generate error)

ifeq($(error),L6220E):
             gcc -o ...

有什么办法吗?

【问题讨论】:

    标签: makefile compiler-errors out-of-memory


    【解决方案1】:

    您可以在任何命令前加上- 以向make 表明此命令可以失败:

    normal_target:
             -gcc -o main main.c
             next command here
    

    另一种方法是简单地测试命令中的失败:

    normal_target:
             if gcc -o main main.c; then \
                echo succeeded; \
             else \
                echo compilation failed; \
                gcc -o ...; \
             fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      相关资源
      最近更新 更多