.title		Using the GNU Compiler Collection
.author		Vinayak Hedge | http://linuxgazette.net/authors/vinayak.html

This text derived from LinuxGazette (linuxgazette.net) #120.
Only to show current features of Web Documentation Typesetter.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
.sect		Introduction to GCC

The GNU C compiler is an integral part of the GNU system and was
initially written by Richard Stallman. At first it only compiled C code.
Later a group of volunteers started maintaining it and GCC gained the
ability to support different languages such a C++, Fortran, Ada and Java.
It was then renamed to GNU Compiler Collection to signify this change.
In this article we shall look at mainly the C language compiler.

GCC is not only available on Linux but also on other Unix-like systems
such as FreeBSD, NetBSD,OpenBSD as well as on Windows via Cygwin, MingW32
and Microsoft Services for Unix. It supports a wide variety of platforms
such as the Intel x86 Architecture, AMD x86-64 ,Alpha and SPARC
architectures. Due to this versatility of GCC, it is often used for cross
compiling code for different architectures. Since the GCC source code
is available and modular, it can easily be modified to emit binaries
for obscure or new platforms, such as those used in embedded systems.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
.sect		Basic compilation options

If GCC is available on your system, you can give the following command
to see with what options it has been compiled with.

*|Command 1 - GCC specification and supported functionality|*

.src
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr \
--with-local-prefix=/usr/local --infodir=/usr/share/info \
--mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada \
--disable-checking --libdir=/usr/lib --enable-libgcj \
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib \
--with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux
Thread model: posix
gcc version 3.3.3 (SuSE Linux)
.esrc

This gives a lot of information about GCC. You can see that the POSIX
threading model is supported by this version so you can compile multi-threaded
applications with it. It can also compile code written in C,C++,Fortran-77,
Objective C, Java and Ada. Notice that the C++ include path is also specified,
and that Java code can be compiled to native binaries with libgcj.

Let us write a small C program with a header file to see the various
compilation options GCC supports.

.src
// helloworld.h
#define COUNT 2

static char hello[] = "hello world";
.esrc
.src
// helloworld.c
#include <stdio.h>
#include "helloworld.h"
 
int main()
{
    int i;
    for(i = 0;i <= COUNT; i++)
    { 
        printf("%s - %d\n",hello,i);
    }
    return 0;
}
.esrc

To compile the helloworld program to an object file we can give the command

*|Command 2 - Creating an Object File|*

.src
$ gcc -v -c helloworld.c
...[output snipped]
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/cc1 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 \
-D__GNUC_PATCHLEVEL__=3 helloworld.c -quiet -dumpbase helloworld.c -auxbase helloworld \
-version -o /tmp/ccHmbDAJ.s
GNU C version 3.3.3 (SuSE Linux) (i586-suse-linux)
        compiled by GNU C version 3.3.3 (SuSE Linux).
GGC heuristics: --param ggc-min-expand=42 --param ggc-min-heapsize=23825
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/i586-suse-linux/3.3.3/include
 /usr/i586-suse-linux/include
 /usr/include
End of search list.
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/../../../../i586-suse-linux/bin/as -V -Qy \
-o helloworld.o /tmp/ccHmbDAJ.s
GNU assembler version 2.15.90.0.1.1 (i586-suse-linux) using BFD version 2.15.90.0.1.1
20040303 (SuSE Linux)
.esrc
