August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.

Slides:



Advertisements
Similar presentations
Technotronics GCECT '091 Decode C This is a C Programming event, where you will be given problems to solve using C only. You will be given a Linux system.
Advertisements

Compiling. Your C, C++ or Fortran program won’t work unless you compile it The compiler will build your program as an executable file (typically in the.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
ECE 353 WinAVR and C Debugging Tutorial By Adam Bailin ECE 353 Fall ‘06.
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
Guide To UNIX Using Linux Third Edition
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
1 CS 161 Introduction to Programming and Problem Solving Chapter 10 g++ Compiler Usage Herbert G. Mayer, PSU Status 10/21/2014.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Make: the good, the bad, and the ugly Dan Berger Titus Winters
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Programming With C.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
C Tutorial - Program Organization CS Introduction to Operating Systems.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
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.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
Dissecting the Windows CE Build Process James Y. Wilson Principal Engineer, Windows Embedded MVP CalAmp, Inc. James Y. Wilson Principal Engineer, Windows.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
Multiple File Compilation and linking By Bhumik Sapara.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
Lecture 1: Introduction UNIX programming environment –Editors –Remote shell setup –C compilers –Debugger –make.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
January 27, 2005Serguei A. Mokhov, 1 General Assignment Guidelines and Marking Scheme COMP444 – System Software Design Revision.
系統程式 System Programming 羅習五 國立中正大學資訊工程學系 Class: EA-001 (05) ext.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Introduction to GCC Department of Radio Physics and Electronics ILug-Cal Introduction to GCC Department of Radio Physics and Electronics, Calcutta University.
Makefiles CSSE 332 Operating Systems
Introduction to C Topics Compilation Using the gcc Compiler
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to C Topics Compilation Using the gcc Compiler
GCC: the GNU Compiler Collection
CS1010 Programming Methodology
Introduction to C Topics Compilation Using the gcc Compiler
CS1010 Programming Methodology
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Getting Started: Developing Code with Cloud9
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
CMPSC 60: Week 4 Discussion
Appendix F C Programming Environment on UNIX Systems
Compiler vs linker The compiler translates one .c file into a .o file
Introduction to C Topics Compilation Using the gcc Compiler
Debugging.
Makefiles, GDB, Valgrind
GCC: the GNU Compiler Collection
SPL – PS1 Introduction to C++.
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Presentation transcript:

August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004

August 7, 2003Serguei A. Mokhov, 2 Contents Intro Options Examples

August 7, 2003Serguei A. Mokhov, 3 What is gcc? gcc –stands for GNU C/C++ Compiler –a popular console-based compiler for *NIX platforms and others; can cross-compile code for various architectures –gcc to compile C programs; g++ for C++ –can actually work with also ADA, Java, and a couple other languages –gcc performs all of these: preprocessing, compilation, assembly, and linking –we are to use it for our last C assignment As always: there is man gcc

August 7, 2003Serguei A. Mokhov, 4 Options There are zillions of them, but there are some the most often used ones: –To compile: -c –Specify output filename: -o –Include debugging symbols: -g –GDB friendly output: -ggdb –Show all (most) warnings: -Wall –Be stubborn about standards: -ansi and -pedantic –Optimizations: -O, -O*

August 7, 2003Serguei A. Mokhov, 5 Options: -c gcc performs compilation and assembly of the source file without linking. The output are usually object code files,.o; they can later be linked and form the desired executables. Generates one object file per source file keeping the same prefix (before.) of the filename.

August 7, 2003Serguei A. Mokhov, 6 Options: -o Places resulting file into the filename specified instead of the default one. Can be used with any generated files (object, executables, assembly, etc.) If you have the file called source.c; the defaults are: –source.o if -c was specified –a.out if executable These can be overridden with the -o option.

August 7, 2003Serguei A. Mokhov, 7 Options: -g Includes debugging info in the generated object code. This info can later be used in gdb. gcc allows to use -g with the optimization turned on (-O) in case there is a need to debug or trace the optimized code.

August 7, 2003Serguei A. Mokhov, 8 Options: -ggdb In addition to -g produces the most GDB- friendly output if enabled.

August 7, 2003Serguei A. Mokhov, 9 Options: -Wall Shows most of the warnings related to possibly incorrect code. -Wall is a combination of a large common set of the -W options together. These typically include: –unused variables –possibly uninitialized variables when in use for the first time –defaulting return types –missing braces and parentheses in certain context that make it ambiguous –etc. Always a recommended option to save your bacon from some “hidden” bugs. Try always using it and avoid having those warnings.

August 7, 2003Serguei A. Mokhov, 10 Options: -ansi and -pedantic For those who are picky about standard compliance. -ansi ensures the code compiled complies with the ANSI C standard; -pedantic makes it even more strict. These options can be quite annoying for those who don’t know C well since gcc will refuse to compile unkosher C code, which otherwise it has no problems with.

August 7, 2003Serguei A. Mokhov, 11 Options: -O, -O1, -O2, -O3, -O0, -Os Various levels of optimization of the code -O1 to -O3 are various degrees of optimization targeted for speed If -O is added, then the code size is considered -O0 means “no optimization” -Os targets generated code size (forces not to use optimizations resulting in bigger code).

August 7, 2003Serguei A. Mokhov, 12 Options: -I Tells gcc where to look for include files (.h). Can be any number of these. Usually needed when including headers from various-depth directories in non-standard places without necessity specifying these directories with the.c files themselves, e.g.: #include “myheader.h” vs. #include “../foo/bar/myheader.h”

August 7, 2003Serguei A. Mokhov, 13 For Your Assignments For your assignments, I’d strongly suggest to always include -Wall and -g. Optionally, you can try to use -ansi and – pedantic, which is a bonus thing towards your grade. Do not use any optimization options. You won’t need probably the rest as well.

August 7, 2003Serguei A. Mokhov, 14 Example For example, if you have the following source files in some project of yours: –ccountln.h –ccountln.c –fileops.h –fileops.c –process.h –process.c –parser.h –parser.c You could compile every C file and then link the objet files generated, or use a single command for the entire thing. –This becomes unfriendly when the number of files increases; hence, use Makefiles! NOTE: you don’t NEED to compile.h files explicitly.

August 7, 2003Serguei A. Mokhov, 15 Example (2) One by one: –gcc -g -Wall -ansi -pedantic -c ccountln.c –gcc -g -Wall -ansi -pedantic -c parser.c –gcc -g -Wall -ansi -pedantic -c fileops.c –gcc -g -Wall -ansi -pedantic -c process.c This will give you four object files that you need to link and produce an executable: –gcc ccountln.o parser.o fileops.o process.o -o ccountln

August 7, 2003Serguei A. Mokhov, 16 Example (3) You can do this as well: –gcc -g -Wall -ansi -pedantic ccountln.c parser.c fileops.c process.c -o ccountln Instead of typing this all on a command line, again: use a Makefile.

August 7, 2003Serguei A. Mokhov, 17 Example (4) # Simple Makefile with use of gcc could look like this CC=gcc CFLAGS=-g -Wall -ansi -pedantic OBJ:=ccountln.o parser.o process.o fileops.o EXE=ccountln all: $(EXE) $(EXE): $(OBJ) $(CC) $(OBJ) -o $(EXE) ccountln.o: ccountln.h ccountln.c $(CC) $(CFLAGS) -c ccountln.c...