问题
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:
which gcc- will print a patch to GCC (copy it to clipboard)mkdir somedir; cd somedir- 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.cbefore every line that came to gcc. chmod +x gcc- set execution rights to gcc wrapper- 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