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]

1:



how can I Limit mysql to single cpu, to allow hardware benchmarking
You can also use the implicit rules of make, so that 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 pthread
To add flags to this define the variable CFLAGS in your environment, e.g.


pthread_create memory leak
in 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, but for C compilation you can get away with just listing dependancies so long as one of them has the same base name as a target..
Boost::Interprocess Shared Memory Bus Error
For example 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..


2:


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.


3:


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..


4:


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..


5:


You can use a shell script that takes some 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 that 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, something 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 trying to compile code that someone 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