Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.

Similar presentations


Presentation on theme: "ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material."— Presentation transcript:

1 ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 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 2 What’s This Blue Code? #include // 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 3 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

5 4 Typical GCC compilation options: OptionDescription -std=xxx –std=c90 to compile to ISO C90 standard –std=c99 to compile to ISO C99 standard –std=gnu90 to compile to GNU C90 standard –std=gnu99 to compile to GNU C99 standard -ansi Same effect as –std=c90 -pedantic Issue warning if C source is not strictly ISO compliant -Wall Issue warnings on all questionable C constructs -lm Link to the standard math library (required for some UNIX systems) -o exec_file Determines the name of the executable file (can be different from the source file name) If -o is omitted, the default name is a.out (or a.exe).

6 5 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

7 6 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

8 7 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

9 8 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.

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

11 10 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


Download ppt "ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material."

Similar presentations


Ads by Google