This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pass bash variable as argument to gcc


On 2015-10-29, staticx <mohamedboussaa3@gmail.com> wrote:
> I wonder if I can pass the content of a bash variable as an argument to gcc.
> My variable is a list of optimization options like $var="-opt1 -opt2 -opt3"
> gcc $var test.c -o object.o didn't work

What do you mean by `didn't work'? This worked for me:

$ ll
total 4.0K
-rw-r--r-- 1 ja ja 405 Oct 29 14:33 main.c
$ export VAR="main.c -o PROG -O2 -g"
$ gcc $VAR
$ ll
total 16K
-rw-r--r-- 1 ja ja 405 Oct 29 14:33 main.c
-rwxr-xr-x 1 ja ja 11K Oct 29 14:43 PROG

You just can't do:

 $ VAR="main.c -o PROG -O2 -g"  gcc $VAR
gcc: fatal error: no input files
compilation terminated.

because $VAR will expanded at the very beginning before it is defined
and will be empty. This not gcc problem, it's how Bash works.

-- 
Arkadiusz Drabczyk <arkadiusz@drabczyk.org>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]