3

On Linux, is there a way to pass arguments to gcc from a file. That is to gave file like compile.args

% cat compile.args
-g3
-ggdb
 -pedantic
 -pedantic-errors
 -Wall
 -Werror
 -O0
 vec1.cpp
 -o vec1

and then give this file to g++/gcc. I can do this using cat compile.args | xargs g++, is they any other way? Does gcc support this?

thanks.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
eran
  • 6,731
  • 6
  • 35
  • 52

2 Answers2

8

Yes, just run gcc @compile.args

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
1

For verbosity, also something like this should work (depending on running shell)

g++ `cat compiler.args|xargs`

or

COMPILE_ARGS=`cat compiler.args|xargs` g++ ${COMPILE_ARGS}
rasjani
  • 7,372
  • 4
  • 22
  • 35
  • Why exactly are you trying to run the output of cat through xargs? It works fine without. – thiton Oct 27 '11 at 09:24
  • 1) Habit and 2) explicit removal of linefeeds. =) – rasjani Oct 27 '11 at 09:30
  • Why would you do this when gcc already has direct support for doing this via the `@` command line option ? – Paul R Oct 27 '11 at 09:31
  • 3
    Because people do use other compilers too than gcc and having or atleast knowledge of how to archive the same functionality will help in porting and/or writing build scripts that would be easier to port. More people do know about shell expansion than gcc commandline options and i sorta thought that stackoverflow is about gaining and sharing knowledge .. – rasjani Oct 27 '11 at 09:39