Help:Gcc compiler
From MMAE
Gcc includes a family of compiler front and back ends, supporting many languages including C, C++, java, and fortran for a number of processors. Only C and C++ are documented by this page, but other front ends are at least listed. Check the main documentation for additional details.
- Vendor homepage
- http://freshmeat.net/gcc
- Software homepage
- http://
- Availability
- unix, windows via cygwin
- The main gcc suite should be installed on all unix machines. Ask if you need a front end that is not installed, or if it is not installed at all.
- commands
- gcc g++ g77 gcj gcjh gcov gij grepjar jar jcf-dump jv-convert jv-scan rmic rmiregistry
- Other related software
- emacs
- gdb
- View online documentation
- man pages
- info docs viewable in emacs
- info --directory=/opt/gcc-342/info
- Example files
- Help:C examples
[edit] Basic details
The C compiler installed on these systems is the freeware gcc compiler. This compiler differs somewhat from the commercial Sun compiler. The command to run the compiler is:
gcc options... source files...
- -o filename
- name the output executable filename instead of a.out
- -O2
- use the maximum optimization level to reduce execution time
- -g
- include extra debugging symbols to allow the use of gdb or dbx
- -Wall
- turn on almost all useful warnings; this may catch bugs and portability problems in your code
- -c
- compile source to object file, do not link (for independantly compiling a single module of a multiple source file project)
For example, to compile a file called prog.c, use the command
- gcc -O2 prog.c
which would compile prog.c with the highest level of optimization, and save the result in the executable a.out.
[edit] Using C++
gcc supports both C and C++. If you wish to compile a C++ program, use 'g++' instead of gcc, and use the '.cpp' or '.C' extension instead of the '.c' extension. The same options as above may be used.
Read the man page for gcc and g++ for additional information.
Examine these simple C examples.
[edit] References
- The C Programming Language, Khernigan & Ritchie
- The C++ Programming Language, Bjarne Stroustrup (second edition)
- The Posix Programmer's Guide, Donald Lewine
- several other unix books from O'Reilly & Associates
