
Chapter 3.
Developing with Red Hat Enterprise Linux
Developer Tools
Use the tutorials in this chapter to learn about standard native development with the tools.
See http://www.redhat.com/docs/manuals/gnupro/ for details about the tools.
3.1. Create Source Code
To start, create the following sample source code file and save it as hello.c. The following sections
show you how to compile this file to form an executable and how to run it.
#include <stdio.h>
int a, c;
static void
foo (int b)
{
c = a + b;
printf ("%d + %d = %d\n", a, b, c);
}
int
main (void)
{
int b;
a = 3;
b = 4;
printf ("Hello, world!\n");
foo (b);
return 0;
}
Example 3-1. Source code to save as hello.c
3.2. Compile, Assemble, and Link from Source Code
To compile the code, use the following command:
gcc -g hello.c -o hello
The -g option generates debugging information and -o specifies the name of the executable to be pro-
duced. Both of these can be omitted. Other useful options include -O to enable standard optimizations
and -O2 for extensive optimizations. If no -O is specified, GCC will not optimize.
See Using the GNU Compiler Collection (GCC) for additional basic compiler information.
Kommentare zu diesen Handbüchern