syntagma
syntagma

Reputation: 24354

Configure GCC to add compile flags globally

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.

Upvotes: 2

Views: 5209

Answers (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

Upvotes: 2

Laser
Laser

Reputation: 6960

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

Upvotes: 1

Related Questions