Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

NOTE: CentOS Enterprise Linux is built from the Red Hat Enterprise Linux source code. Other than logo and name changes CentOS Enterprise Linux is compatible with the equivalent Red Hat version. This document applies equally to both Red Hat and CentOS Enterprise Linux.

2.4. gcc, the GNU Compiler Collection

The GNU Compiler Collection (GCC), is a complete set of tools for compiling programs written in C, C++, Objective C, or languages for which you have installed front-ends. The GNU compiler uses the following utilities:

To invoke the compiler, type:

gcc option, option...

Each option signifies input that allows you to control how the program compiles (for example, you can interrupt a compile process at intermediate stages). Use commas to separate options. There are many options available that provide specific types of compiled output, some for preprocessing, others controlling assembly, linking, optimization, debugging, and still others for target-specific functions. For instance, call the compiler with a -v option to refer to precisely which options are in use for each compilation pass.

gcc implicitly recognizes the following file extensions:

  • .c (for C source code that must be preprocessed)

  • .C (for C++ source code that must be preprocessed)

  • .s (for assembler code)

  • .S (for assembler code that must be preprocessed).

When referring to C++ compilation, g++ is its customary name. Because there is only one compiler, it is also accurate to use the gcc call, no matter what the language context. The g++ distinction is more useful when the emphasis is on compiling C++ programs, with the GNU compiler acting not merely as a preprocessor, but building object code directly from your C++ program source.

There is no intermediate C version of the program; avoiding an intermediate C representation of the program means that you get better object code and better debugging information. The GNU debugger works with this information in the object code to give you comprehensive C++ source-level editing capabilities.

When you compile C or C++ programs, the compiler inserts a call at the beginning of main to a _ _main support subroutine. To avoid linking to the standard libraries, specify the -nostdlib option. (Including -lgcc at the end of your compiler command line resolves this reference and links only with the compiler support library libgcc.a; ending your command's input with it ensures that you get a chance to link first with any of your own special libraries).

_ _main is the initialization routine for C++ constructors. Because GNU C is meant to interoperate with GNU C++, even C programs must have this call; otherwise, C++ object files linked with a C main might fail.

Compilation can involve up to four stages, always in the following order:

  • preprocessing

  • compiling

  • assembling

  • linking

The first three stages apply to an individual source file: preprocessing establishes the type of source code to process, compiling produces an object file, assembling establishes the syntax that the compiler expects for symbols, constants, expressions and the general directives. The last stage, linking, completes the compilation process, combining all object files (newly compiled, and those specified as input) into an executable file.

For more information on the GNU compiler and its options, refer to Using the GNU Compiler Collection (GCC).

 
 
  Published under the terms of the GNU General Public License Design by Interspire