开发者

Make gcc/g++ use absolute path for warnings when compiling files in pwd

开发者 https://www.devze.com 2023-02-24 09:56 出处:网络
Is there a way to make gcc use the absolute path when printing errors found in files compiled in the current directory?

Is there a way to make gcc use the absolute path when printing errors found in files compiled in the current directory?

For instance the following does what I want when print errors:

g++ -I. -I../../.. /home/some/path/somefile.cpp

but I want to achieve the same with some开发者_Python百科thing like:

g++ -I. -I../../.. somefile.cpp

I want warnings and errors to be formatting something like:

/home/some/path/somefile.cpp:299:52: warning: some warning


There is no way to do this with gcc itself, but it's trivial with a wrapper script, installed as "gcc", "g++", etc in a directory before /usr/bin in your PATH:

#! /bin/sh
sourcefile="$1"; shift
case "$sourcefile" in
    /*) ;;
    *) sourcefile="$PWD/$sourcefile" ;;
esac
exec "/usr/bin/${0##*/}" "$sourcefile" "$@"

... provided that you always put the source file first in your compiler invocation (you'll have to tweak your Makefiles).

0

精彩评论

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

关注公众号