Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Guide de l'utilisateur Page 55

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 100
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 54
Running GCC
45
}
The following procedure illustrates the compilation process for C++ in its most basic form.
Procedure 4.2. Compiling a 'Hello World' C++ Program
1. Compile hello.cc into an executable with:
g++ hello.cc -o hello
Ensure that the resulting binary hello is in the same directory as hello.cc.
2. Run the hello binary, i.e. hello.
4.1.6.3. Simple Multi-File Usage
To use basic compilation involving multiple files or object files, start with the following two source files:
one.c
#include <stdio.h>
void hello()
{
printf("Hello world!\n");
}
two.c
extern void hello();
int main()
{
hello();
return 0;
}
The following procedure illustrates a simple, multi-file compilation process in its most basic form.
Procedure 4.3. Compiling a Program with Muiltiple Source Files
1. Compile one.c into an executable with:
gcc -c one.c -o one.o
Ensure that the resulting binary one.o is in the same directory as one.c.
2. Compile two.c into an executable with:
gcc -c two.c -o two.o
Ensure that the resulting binary two.o is in the same directory as two.c.
3. Compile the two object files one.o and two.o into a single executable with:
gcc one.o two.o -o hello
Ensure that the resulting binary hello is in the same directory as one.o and two.o.
4. Run the hello binary, i.e. hello.
Vue de la page 54
1 2 ... 50 51 52 53 54 55 56 57 58 59 60 ... 99 100

Commentaires sur ces manuels

Pas de commentaire