Stop multiple file GCC compilation when one of them fails

孤人 提交于 2020-01-25 21:29:06

问题


I have created the following bash build script file :

BLD_INCLUDE="-I..source/module1 -I..source/module2"
SRC_MOD1="$(find ../source/module1 -name '*.c')"
SRC_MOD2="$(find ../source/module2 -name '*.c')"
BLD_SOURCES="../source/program.c $SRC_MOD1 $SRC_MOD2"
BLD_LINKER="" #if there is any need of linker - irrelevant here
gcc $BLD_FLAGS $BLD_INCLUDE -o outputobject $BLD_SOURCES $BLD_LINKER

I am building like this because there are lot of files I need to compile.

The problem is, when executing multiple files using gcc, like above, if the compilation of one of the files fails, it prompts for the error along with "compilation terminated" and then continues executing other files.

The behaviour I want is, that even if one of the file fails to compile, whole compilation stops.

That is, in my case : suppose there is a header file missing. Now gcc tries to compile the very first .c , finds that the header file is missing, prompts

fatal error : file missing error compilation terminated.

and then continues with execution of other .c files. Since the header file is missing in all, it keeps on giving me this error and continues execution.

I want this build script to terminate as soon as compilation fails even of one of the files.

Edit : Not a duplicate of Stop GCC on error with multiple files compilation, it originated from this very question itself (read comments). The question even refers back to this.

来源:https://stackoverflow.com/questions/41182124/stop-multiple-file-gcc-compilation-when-one-of-them-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!