Developing With Red Hat Enterprise Linux Developer Tools; Create Source Code; Compile, Assemble, And Link From Source Code; Run The Executable - Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Manual

Developer tools guide
Hide thumbs Also See for ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE:
Table of Contents

Advertisement

Developing with Red Hat Enterprise Linux
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
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

3.2. Compile, Assemble, and Link from Source Code

To compile the code, use the following command:
gcc -g hello.c -o hello
The
option generates debugging information and
-g
duced. Both of these can be omitted. Other useful options include
and
for extensive optimizations. If no
-O2
See Using the GNU Compiler Collection (GCC) for additional basic compiler information.
hello.c
specifies the name of the executable to be pro-
-o
is specified, GCC will not optimize.
-O
Chapter 3.
Developer Tools
. The following sections
hello.c
to enable standard optimizations
-O

Advertisement

Table of Contents
loading

Table of Contents