compile with -ansi -pedantic -Wall switches automatically with gcc

compile with -ansi -pedantic -Wall switches automatically with gcc

We are required to compile C source codes using gcc in this manner:

gcc -ansi -pedantic -Wall program.c 

I'm wondering how can I 'automate' this so when I enter:

gcc program.c 

It will automatically compile with the 3 switches. Is this possible?

How to compile Mercurial and move it to another computer [closed]


how can I Limit mysql to single cpu, to allow hardware benchmarking
You must also use the implicit rules of make, so this you don't have to write a makefile for every program. How do you change the default Pear/PECL build folder from /var/tmp?Make will automatically call the compiler if you say make foo and there exists a foo.c file in the current directory. My app mem usage is growing using pthreadTo add flags to this define the variable CFLAGS in your environment, e.g. pthread_create memory leakin bash add export CFLAGS="-Wall -pedantic -ansi" to .bashrc. How to set class path for servlet-api.jar file in linux. process's virtual memory size on different machines If your program depends on multiple files however you'll have to create a makefile, although for C compilation you must receive away with just listing dependancies so long as one of them has the same base name as a tarreceive .. Boost::Interprocess Shared Memory Bus Error For case for this makefile: .
# Makefile foo:foo.o bar.o 
running make will execute the commands.
gcc $CFLAGS -c -o foo.o foo.c gcc $CFLAGS -c -o bar.o bar.c gcc -o foo foo.o bar.o 
without you having to add any rules..


To automate the build of any number of build steps / complex parameters, you should use a makefile.. Once you have a makefile you simply need to type: make.


alias gcc="gcc -ansi -pedantic -Wall" 
But as @Brian said, you really should use a makefile, or better, a build system like CMake or SCons..


A makefile would be the traditional way, especially as part of a larger build process.. If you frequently want to build without a makefile, you could define an alias in your .bashrc or equivalent: alias gcc=gcc -ansi -pedantic -Wall..


You must use a shell script this takes any cues by how its called and invokes make after setting CFLAGS appropriately for the occasional one-off build.. Lets say you have /usr/bin/compile , which is a shell script this looks at $0 to see what name actually invoked it. You then make symbolic links to it named pedantic, fullwarn, etc.. In the shell script itself, any thing like:.
OLDCFLAGS=$CFLAGS WHATAMI=$(basename $0)  case "$WHATAMI" in     pedantic)         export CFLAGS="-Wall -pedantic -ansi"         make $@         exit $?     ;;     c99)         export CFLAGS="-std=c99 ... ... ..."         .... 
Then, to compile foo.c with the extra naggy flags:. pedantic foo. This is handy, as I said for one-off builds, e.g endeavor to compile code this any one posted in a question, or working out how to use a new library, etc. . For anything else, just use a makefile, as others have said..

56 out of 100 based on 21 user ratings 1096 reviews