CS 311 - Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.

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

Utilizing the GDB debugger to analyze programs Background and application.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating.
Guide To UNIX Using Linux Third Edition
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 9.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
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”
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Xin Liu Sep 16, Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
C Program Toolchain #1 Dr. Michael L. Collard 1.
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.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
TAMU CSCE 313 (the basics). Basic Unix/Linux programming Accessing CS systems  PuTTY (putty.exe) – a Telnet and SSH client  Common hosts: unix.cs.tamu.edu.
Active-HDL Interfaces Debugging C Code Course 10.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
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.
Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes.
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
cs33201 Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003.
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?
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
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.
LINUX System : Lecture 5 text editor, compilation (make), … Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
CSCI 4061 Recitation 2 1.
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Large Program Management: Make; Ant
Debugging with gdb gdb is the GNU debugger on our CS machines.
gdb gdb is the GNU debugger on our CS machines.
Operating System Discussion Section.
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
Debuggers.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
Getting Started: Developing Code with Cloud9
Unix Programming Environment
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Makefiles and the make utility
CSC 253 Lecture 15.
Debugging.
Makefiles, GDB, Valgrind
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.
Large Program Management: Make; Ant
Presentation transcript:

CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS Operating Systems I

Compiling programs using gcc GCC stands for GNU Compiler Collection. Used to compile different programming languages like C, C++, Java, Fortran Contains a large set of options. Frequently used options to compile C programs – -c, -g, -lm, -o, -Wall, -ansi – -c – compiles the file to create an object file (.o) but does not perform linking. – -o – generates executable file – Ex: gcc –c file.c – gcc file.o –o exec_file Lecture 112CS Operating Systems I

Compiling using gcc More options – -lm – compile programs that uses mathematical functions – -g – Generate symbolic info to be used with gdb – -Wall – generate all warnings – -ansi – use strict ANSI coding standards for C To link multiple files together – Ex. gcc –c file.c-g –Wall #creating.o for file1 – gcc –c file2.c –g –Wall#creating.o for file2 – gcc file1.o file2.o –o exec_file#linking both object files Lecture 11CS Operating Systems I3

Archiving modules Useful when a project has several hundred object modules. Archiving modules helps us to categorize the modules. Archived file names must have “.a” extension. Archives can be used with gcc. Only the needed object modules are linked automatically as necessary, Archiving utility in UNIX – ar Lecture 11CS Operating Systems I4

Archive utility - ar “ar” allows us to create and manipulate archives. Syntax: ar key archiveName.a {filename}* – Key d – delete a file from archive q – appends a file to the end of archive even if its present r – adds/replaces a file to the archive s – builds an index for archive for faster access t – displays archive’s contents x – copies a list of files from archive to current directory v – generates verbose output – Ex: ar r myArchive.a file1.o file2.o #add 2 files to myArchive.a gcc myArchive.a –o file_exec Lecture 11CS Operating Systems I5

Indexing archives If a module A requires a function from module B then B should be present before A in the archive. To workaround this out-of-order problem, index the archives using ‘s’ key – Ex: ar s myArchive ‘s’ key creates an index to the archive which makes access faster. Lecture 11CS Operating Systems I6

Using Makefiles Makefiles are helpful in managing dependencies. Generally such files are named as “GNUMakefile”, “makefile” or “Makefile” To execute makefiles use the utility “make”. “make” will automatically look for “GNUMakefile”, “makefile” or “Makefile”. To use your own filename for makefiles use ‘–f’ option to execute it. – Ex: make –f myFile Lecture 11CS Operating Systems I7

Makefile rules Use of makefile – Ex: Assume we have these files heap.h, heap.c, mainHeap.c – Without using makefiles we compile the code like this gcc –c heap.c gcc –c mainHeap.c gcc mainHeap.o heap.o -o heap_exec – Changing any of the files will result in compiling the program all over again. (tedious when there are large number of files) – Using “make” the task is simplified. Rules for creating makefile – Simplest form of makefile Targetlist: dependencylist commandlist(commandlist should have a tab-space before it) Lecture 11CS Operating Systems I8

Creating makefiles Makefile for the previous example will be heap.o: heap.c heap.h gcc –c heap.c -g –Wall mainHeap.o: mainHeap.c heap.h gcc –c mainHeap.c -g –Wall heap_exec: heap.o mainHeap.o gcc heap.o mainHeap.o -o heap_exec We can execute this by simply typing “make”. Makefile compiles only the file that has been changed. Lecture 11CS Operating Systems I9

More on makefiles Using macros CFLAGS = -g –Wall#defining a macro OBJECT = file1.o file2.o file3.o file4.o SOURCE = file1.c file2.c file3.c file4.c heap.o: heap.c heap.h gcc –c heap.c $(CFLAGS)#using macro Maintaining archive myArchive.a: $(OBJECT)#creating an archive ar –r myArchive.a $(OBJECT) heap: heap.o myArchive.a(file2.o file1.o) #using files from archive Lecture 11CS Operating Systems I10

Debugging using gdb To debug a program gdb utility provides – Running and listing program – Setting breakpoints – Examining variable values – Tracing execution To run gdb use the command ‘gdb’ from terminal. Useful commands with gdb – help – list all commands – list – display the program – break #linenum – setup breakpoints – data – to watch the contents of variables, arrays – run – to execute the program Lecture 11CS Operating Systems I11