1

I have few flags I want to add to my gcc compilation, so I aliased them as

alias gcc_flags='-std=c99 -Wall -pedantic -Wextra -Wconversion'

and tried to compile like this:

$ gcc gcc_flags file_name.c -o object_name -L/usr/lib/i386-linux-gnu -lcurl
gcc: error: gcc_flags: No such file or directory

When compiling without the alias, i.e.

gcc -std=c99 -Wall -Wextra -Wconversion -pedantic file_name.c -o object_name -L/usr/lib/i386-linux-gnu -lcurl

the compilation works just fine. Why is that?


  • gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
  • alias gcc_flags='-std=c99 -Wall -pedantic -Wextra -Wconversion' appears on my alias list
  • Ubuntu version - Release: 14.04

By the way, isn't it about time for gcc to compile with -std=c99 by default?

dessert
  • 39,982

1 Answers1

2

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. (man bash, emphasis mine)

To create an alias for gcc with custom flags, do it like so instead:

alias gcc_flags='gcc -std=c99 -Wall -pedantic -Wextra -Wconversion'

And run your command as:

gcc_flags file_name.c -o object_name -L/usr/lib/i386-linux-gnu -lcurl

If there are options you keep adding every time and feel should be default, you can also add an alias for gcc itself, e.g.:

alias gcc='gcc -std=c99'

This way gcc will always be started with that flag. If you then want to ignore the alias and use it without that flag you can run it as \gcc or in a number of different ways listed in How can I run original command that aliased with same name?.

dessert
  • 39,982