Pick a Free OS

User login

Navigation

GCC options you should know

Writing a thousand line code is better than having to debug it. The mistakes can vary from a missing ";" error to major errors of logic. At the end of the day, code that refuses to run is merely a temp file waiting to be deleted!

Given below are the most often used gcc options. Though a lot more exist, these are the most commonly used ones (26 to be specific) and can make debugging easier.

For more information refer to the man pages type "man gcc" at the command line. GCC offers a host of options, some even for the AMD-K62 processor.

The common syntax is gcc [option] [filename]. All options listed below are case sensitive. The option -v differs completely from -V . Also options may be put together in pairs. So, -vc is different from -v -c.

1) Extensions do matter: The extension given to a file determines its type and the way it should be compiled.

.c => c source file - preprocess, combine and assemble.

.m => objective-c source file - preprocess, combine and assemble.

.i => pre-processed C file - compile and assemble.

2) -x language [c, c++, objective-c etc.] - Compiles the file with respect to the given option. A file with '.m' extension can be compiled as a '.c' extension file using the command "gcc -x c filename.m". If no language is specified the file is compiled depending upon the extension.

3) -c : Compiles without linking. All successfully compiled binaries are saved as "filename.o".

4) -S : Stop after compilation and generate the assembly code. This code will be saved in a file with the extension ".s". A extract of the assembler code is given below.

main:

pushl %ebp

movl %esp,%ebp

subl $8,%esp

addl $-12,%esp

pushl $.LC0

5) -o filename: The compiled binary is saved with specified filename. If not specified, the default is the save the binary as a file named a.out in the directory.

6) -v : Provides the release number of your compiler. Useful if one is getting an unexplainable error. The compiler may be a old version.

7) -pipe : For a big program involving a lot of inter linked files and functions, temporary files tend to get created while compilation. When this option is specified, the compiler makes use of pipes rather than creating temporary files. The output of each function is piped to the next. The swap space is used instead.