且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行并行make时出错

更新时间:2023-10-14 11:17:34

如果任何程序被调用, code> make 返回一个错误, make 的返回码不会为零。因此,在调用 make 之后,您只需检查返回代码以查看是否发生错误。在 bash (以及许多其他shell如 zsh ),您可以执行以下操作:

If any program called by make returns with an error, the return code of make will not be zero. So after calling make you could just check the return code to see if an error occurred. On bash (and many other shells like zsh) you could do the following:

# make
....
# echo $?

echo将打印 0

您还可以从shell脚本中运行检查:

You could also run the check from inside a shell script:

make
if [ $? -eq 0 ]; then
    echo "Everything OK"
else
    echo "Something went wrong!"
fi

如果您需要确切的错误消息,最简单的方法是重定向输出 make 到某个文件, grep 则执行失败。

If you need the exact error message the easiest way is to redirect the output from make to some file and grep for the error if execution failed.

但是我通常这样做是并行运行 make ,并用 -j1 如果出错了,我会得到一个干净的错误信息。我想这可以放入一个shell脚本使用上面的技术。

But the way I usually do this is to run make in parallel and re-execute it with -j1 if something went wrong so I will get a clean error message. I guess this could be put into a shell script using the technique above.