If you REALLY want to add -std=c99
every time, you can modify the so-called "spec file" which is a config file for the gcc
command. Note that the gcc
command is actually a compiler driver which only invokes a compiler in a narrower sense (the latter is ccl
or cc1plus
in the case of GCC toolchain.)
Modifying the specs file is a bit tricky nowadays because it exists only inside the binary file of the gcc
command by default. This is because very few people wanted to modify it for their own purpose.
Find paths at which the gcc
command tries to find any spec files in this way,
$ strace -e file gcc 2>&1 | grep specs
access("/usr/lib/gcc/x86_64-linux-gnu/4.6/specs", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/4.6/specs", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/lib/specs", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/lib/gcc/x86_64-linux-gnu/specs", R_OK) = -1 ENOENT (No such file or directory)
and then create a template file at one of the above locations by dumping the built-in specs file:
$ sudo bash -c 'gcc -dumpspecs > /path/to/specs'
At this point, the output from gcc -v
should change from this
$ gcc -v
Using built-in specs.
(...snip...)
to something like
$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/4.6/specs
(...snip...)
Now you need to modify the specs file according to your need. The syntax is indeed cryptic but you can use your imagination. Hint: you should see something like
*cpp_options:
%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w} %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*} %{undef} %{save-temps*:-fpch-preprocess} %(ssp_default)
Look at this part:
%{std*&ansi&trigraphs}
This is where -std=c99
is expanded into before the gcc
command constructs the full command line for the preprocessor cpp
. You should be able to insert -std=c99
just before it so that it works as your own default value for the -std
option. Do the same for *cc1_options
which is actually more important for your purpose.