Re: pass bash variable as argument to gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2015-10-29, staticx <mohamedboussaa3@xxxxxxxxx> 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@xxxxxxxxxxxx>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux