Configure GCC to add compile flags globally

风流意气都作罢 提交于 2019-12-12 06:04:05

问题


Can I configure GCC to add some file globally, for every project? I want to make it temporarily and only with flags like: -fdiagnostics-color.


回答1:


I don't understand why do you need it but you can do a wrapper:

  1. which gcc - will print a patch to GCC (copy it to clipboard)
  2. mkdir somedir; cd somedir
  3. create file with name gcc
    and add into it: full path to gcc(from clipboard) -fdiagnostics-color somefile.c $@ this command will add -fdiagnostics-color somefile.c before every line that came to gcc.
  4. chmod +x gcc - set execution rights to gcc wrapper
  5. And finally add path to your wrapper. export PATH=somedir:$PATH



回答2:


You might read about GCC spec files and alter the spec file used by your particular version of gcc. But this is generally frowned upon.

The usual practice would be to use GNU make and add a CFLAGS += -fdiagnostics-color to your Makefile. BTW with a recent enough GCC this (adding -fdiagnostics-color flag) is not even necessary since (at least by setting your GCC_COLORS environment variable) the default is -fdiagnostics-color=auto



来源:https://stackoverflow.com/questions/28288764/configure-gcc-to-add-compile-flags-globally

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