1 / 11

ECE 103 Engineering Programming Chapter 9 gcc Compiler

ECE 103 Engineering Programming Chapter 9 gcc 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. Syllabus. What ’ s This Blue Code? Compile C Source Code Execute Generated Object Code.

Télécharger la présentation

ECE 103 Engineering Programming Chapter 9 gcc Compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

More Related