SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to GCC Compiler: Compiling and Executing C Programs

imelda-porter avatar
11 diapositives · 259 Views · Nov 02, 2014

This chapter provides a comprehensive guide on using the GCC compiler for C programming. It covers compiling C source code, executing generated executable files, and explains essential syntax and command-line options. Learn how to compile programs with GCC using examples, understand the structure of basic C code, and manage generated object files. This material is drawn from the ECE 103 syllabus, developed to assist students in mastering programming fundamentals with practical examples.

Introduction to GCC Compiler: Compiling and Executing C Programs - slide 1
01 / 11Introduction to GCC Compiler: Compiling and Executing C Programs
1 / 17

Télécharger la présentation

Introduction to GCC Compiler: Compiling and Executing C Programs
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. ECE 103 Engineering ProgrammingChapter 9gcc Compiler Herbert G. Mayer, PSU CS Status 6/30/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

  2. Syllabus • What’s This Blue Code? • Compile C Source Code • Execute Generated Object Code

  3. What’s This Blue Code? #include <stdio.h> // for printf() #define Max 4 short zag = -1; short prime[ Max ] = { 3, 5, 7, 11 }; // initialization void print_prime() { // print_prime short i; for( i = 0; i < Max; i++ ) { printf( " prime[%1d] = %2d\n", i, prime[ i ] ); } //end for printf( " zag = %d\n\n", zag ); } //end print_prime int one() { // one zag++; // side-effect return 1; } //end one main( ) { // main print_prime(); prime[ zag + one() ] = prime[ zag + one() ]; // left or right first? print_prime(); } //end main

  4. Compile Source Code The GNU Project provides a freely available, open source C compiler called gcc Syntax for compiling a program (command line): gcc [options] file_list where: gcc→compiler name (in lowercase) [options] → compilation options (optional) file_list→ list of source and/or object files 3

  5. Typical GCC compilation options: 4

  6. Example: Your source file is called prog1.c. Your compiler generates a default executable file named a.out Type this at the command line (no extra checking): gcc prog1.c -or- Type this at the command line (full checking): gcc -ansi -pedantic -Wall prog1.c 5

  7. Example: Your source file is called mathprog.c. But you prefer the executable file to be named mprog. Then type this command: gcc -ansi -pedantic -Wall mathprog.c –o mprog 6

  8. Example: Your source files are ted.c and alice.c. You want the executable file to be named jupiter2. Type this at the command line: gcc -ansi -pedantic -Wall ted.c alice.c –o jupiter2 7

  9. Execute Generated Object Code If the source file is compiled successfully, an executable (binary) file is created The executable file can be run from the command line in Unix-like environments Syntax for running the executable file: efilename where efilename is the name of the actual file you want to run. 8

  10. If the operating system complains that it cannot find the executable file in the current directory: Prefix the file's name with "./" Syntax: ./efilename 9

  11. Example1: Suppose your executable file is called a.out and it is stored in the current directory To run it, type the following: ./a.out On Unix, this also works: a.out Example2: Suppose your executable file is called prog1 and it is stored in subdirectory HW2 To run it, type the following: HW2/prog1 10