开发者

Possibility to simulate -Werror option behavior with GCC 3.4?

Is there any hope to force GCC 3.4 compiler to make a开发者_Python百科ll warnings into errors like GCC's 4.4 -Werror option does ?

Thanks


You can wrap it and return an error if gcc wrote anything to stderr.

Execute GCC, redirect stderr in a file, cat the file to stderr:

temp=$(tempfile)
trap rm "$temp" EXIT

gcc "$@" 2>"$temp"
ret=$?

cat "$temp" >&2

Return gcc's exit status if it's not 0:

if [ "$ret" != 0 ]; then
    exit $ret;
}

Return 1 if the file is not empty:

if [ $(stat --format=%s "$temp") != "0" ]; then
    exit 1;
}


Ugly hack, just grep "warning:"

gcc files.c 2>&1 | grep "warning:" && exit 1

Replace exit 1 with what it should do when warnings are found.


As @pmg said -

gcc 3.4.6 accepts -Werror (see bottom of manual); gcc 3.3.6 also accepts it !!

Real credits should go to pmg, but thanks for everybody else also :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜