Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003. Original Notes.

Slides:



Advertisements
Similar presentations
GNU gprof Profiler Yu Kai Hong Department of Mathematics National Taiwan University July 19, 2008 GNU gprof 1/22.
Advertisements

Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
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’
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
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.
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
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.
Spring 2014 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
Homework Reading Programming Assignments
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.cpp.
The UNIX development environment CS 400/600 – Data Structures.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Chapter 1 What is UNIX? Graham Glass and King Ables,
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.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
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).
SEEM3460 Tutorial Multi-module programming in C. Copy the material Create the directory mkdir c_multi cd c_multi mkdir ask cd ask Copy files cp ~seem3460/distribute/c_multi-module/ask/ask_reverse.c.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Xuan Guo Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
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?
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael Weeks.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
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.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
CSCI 4061 Recitation 2 1.
Automating Builds with Makefiles
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
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.
Debuggers.
Makefiles and the make utility
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
SCMP Software Development Spring 2018 James Skon
CSc 352: Elementary “make”
Chapter 5 The Bourne Shell
CSc 352 An Introduction to make
Makefiles and the make utility
Debugging.
Makefiles, GDB, Valgrind
SCMP Software Development Spring 2018 James Skon
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.
Review The Unix Shells Graham Glass and King Ables,
Presentation transcript:

Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes by Raj Sunderraman Converted to presentation and updated by Michael Weeks

Compiling in gcc % gcc reverse.c produces executable in a.out % gcc -o reverse reverse.c GNU C Compiler (gcc)‏ 

Multi-module Program types.h supps.h, supps.c parts.h, parts.c sp.h, sp.c db.h, db.c (this has the main() function)‏ Compile these programs separately;  % gcc -c supps.c  % gcc -c parts.c  % gcc -c sp.c  % gcc -c db.c These commands produce supps.o, parts.o, sp.o, db.o % gcc db.o supps.o parts.o sp.o -o db

Unix File-Dependency System: make % make -f fileName Makefiles: consist of a list of interdependency rules of the form: targetList:dependencyList commandList Rules must be separated by at least one line

Unix File-Dependency System: make targetList is a list of target files dependencyList is a list of files on which the files in targetList depend on commandList is a list of zero or more commands, separated by new lines, that reconstruct the target files from the dependency files NOTE: Each line in commandList MUST start with a tab

Example Makefile db: db.o supps.o parts.o sp.o gcc db.o supps.o parts.o sp.o -o db db.o: db.c types.h db.h supps.h parts.h sp.h gcc -c db.c supps.o: supps.c types.h supps.h gcc -c supps.c parts.o: parts.c types.h parts.h gcc -c parts.c sp.o: sp.c types.h sp.h gcc -c sp.c

Order of Make rules The order of make rules is important. The make utility starts from the first rule and creates a tree with target files at the root and the dependency files as children.

Order of Make rules The make utility then works up the tree  From the leaf nodes to the root node  Looking to see if the last modification time of each node is more recent than the last modification time of the immediate parent node  If so, the associated parent's rule is executed

Make Rules Make Rules of the form: xxx.o: reverse.c reverse.h gcc -c xxx.c where xxx varies from each rule Pre-defined rule (how to make.o from.c files):.c.o: /bin/cc -c -O $<

Simplifying Make Files So makefile can be simplified as: db: db.o supps.o parts.o sp.o gcc db.o supps.o parts.o sp.o -o db db.o: db.c types.h db.h supps.h parts.h sp.h supps.o: supps.c types.h supps.h parts.o: parts.c types.h parts.h sp.o: sp.c types.h sp.h

Simplifying Make Files Further simplification (leave out.c files in dependency rules db: db.o supps.o parts.o sp.o gcc db.o supps.o parts.o sp.o -o db db.o: types.h db.h supps.h parts.h sp.h supps.o: types.h supps.h parts.o: types.h parts.h sp.o: types.h sp.h

Touch Utility touch -c {fileName}+  updates the last modification and access times of the named files to the current time. By default, if a specified file does not exist it is created with zero size.  To prevent this default, use -c option. Use touch to force make to recompile files

Archiving Modules GNU archive utility: ar ar key archivename {file}* Creates archive files (.a)‏  Add (r, if file is not there)‏  Remove (d)‏  Replace (r)‏  Append (q) adds to end of archive  Table of contents (t)‏

GNU Profiler Utility gprof profiles a running program  lets you see how the program spends its time Must use -pg option with gcc Creates file gmon.out by default

GNU Debug Utility gdb helps debug a program Must use -g option when compiling gdb programname  Get help (help)‏  Set breakpoints (break line#_or_function)‏  Look at variables (print variable_name)‏  Run a program (run, step, or continue after breakpoint)‏  List a program (list)‏

Strip Utility Utility strip removes extra info from a program Useful after debug / profile strip programname

Review Compiling.c files Including multiple files Using make to compile several related files How to simplify an example makefile touch command