gcc是否可以配置为在警告/错误消息中不打印完整路径?

gcc是否可以配置为在警告/错误消息中不打印完整路径?,gcc,Gcc,当gcc打印出警告或错误时,它会显示包含错误的文件的完整路径。是否有将输出缩短为文件名的标志?这取决于调用gcc的方式: /tmp/c$ gcc -Wall bad.c bad.c:1: warning: return type defaults to ‘int’ bad.c: In function ‘main’: bad.c:1: warning: control reaches end of non-void function 如果有人关心的话。有时候我会使用sed脚本(例如,当使用cma

当gcc打印出警告或错误时,它会显示包含错误的文件的完整路径。是否有将输出缩短为文件名的标志?

这取决于调用gcc的方式:

/tmp/c$ gcc -Wall bad.c bad.c:1: warning: return type defaults to ‘int’ bad.c: In function ‘main’: bad.c:1: warning: control reaches end of non-void function
如果有人关心的话。

有时候我会使用sed脚本(例如,当使用cmake时,它总是使用完整路径)。这也可以用来清理C++中的其他部分日志,F.E.模板名称。

< P>参见包含您的MaMeCuff:< /P>的解决方案的电子邮件线程。

没错,这是可行的,但是如果已经建立了一个复杂的构建系统呢?如果我能在CFLAGS中添加一些东西来清理输出,那就太好了。 /tmp/c$ gcc -Wall /tmp/c/bad.c /tmp/c/bad.c:1: warning: return type defaults to ‘int’ /tmp/c/bad.c: In function ‘main’: /tmp/c/bad.c:1: warning: control reaches end of non-void function /tmp/c$ gcc -Wall ../../tmp/c/bad.c ../../tmp/c/bad.c:1: warning: return type defaults to ‘int’ ../../tmp/c/bad.c: In function ‘main’: ../../tmp/c/bad.c:1: warning: control reaches end of non-void function
main() { }