2016-1-29cs33201 Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003.

Slides:



Advertisements
Similar presentations
The make Utility Programming Tools and Environments Winter 2006.
Advertisements

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.
Week 5 - Wednesday.  What did we talk about last time?  Arrays.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
C Programming Tools Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition,
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
1 The Makefile Utility ABC – Chapter 11,
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.
CS 202 Computer Science II Lab Fall 2009 September 17.
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
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 9.
CS465 - Unix C Programming (cc/make and configuration control)
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Homework K&R chapter 4. HW3: ASCII Hex to Integer int axtoi (char s[ ]) { int i, n, flag; n = 0; flag = 1; for ( i = 0; flag; i++) /* for (i = 0; ; i++)
C Tutorial - Program Organization CS Introduction to Operating Systems.
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.
Exam / Homework Exam 1 Starting K&R chapter 4 tonight
Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes.
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.
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
Tools – Ant-MakeEtc 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Tools 12 – Hamcrest 10/02/
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
Discussion Week 1 TA: Kyle Dewey. Project 0 Walkthrough.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Multiple File Compilation and linking By Bhumik Sapara.
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.
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.
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
1 C Basics. 2 The C Language Spirit Made by professional programmers for professional programmers Very flexible, very efficient, very liberal Does not.
LINUX System : Lecture 5 text editor, compilation (make), … Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
C 프로그래밍 개발 도구. 컴파일러 gnu c compiler 컴파일 gcc sample.c 실행 a.out 실행 파일 지정 컴파일 gcc –o sample sample.c 실행 sample.
1 Ritu Chaturvedi Program Building - Code Organization - Program Distribution Methods 2 Ritu Chaturvedi
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Makefiles CSSE 332 Operating Systems
SEEM3460 Tutorial Unix Introduction.
Automating Builds with Makefiles
Cs288 Intensive Programming in Linux
Makefiles Caryl Rahn.
Multi-module programming in C
CS314 – Section 5 Recitation 1
Command-Line Arguments
Makefiles and the make utility
Chapter 14 - Advanced C Topics
SEEM3460 Tutorial Unix Introduction Xinshi Lin & Zihao Fu
Multi-module programming in C
Multi-module programming in C
Chapter 5 The Bourne Shell
Homework K&R chapter 4.
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
CSC 253 Lecture 15.
SPL – PS1 Introduction to C++.
Review The Unix Shells Graham Glass and King Ables,
Week 5 - Wednesday CS222.
Presentation transcript:

cs33201 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

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

cs33203 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 reverse.c –% gcc -c main1.c These commands produce reverse.o, main1.o % gcc reverse.o main1.o -o main1

cs33204

cs33205 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

cs33206 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

cs33207 Example Makefile #MAKEFILE main1: main1.o reverse.o cc main1.o reverse.o -o main1 main1.o: main1.c reverse.h cc -c main1.c reverse.o: reverse.c reverse.h cc -c reverse.c /* REVERSE.C */ #include #include "reverse.h" void reverse (before, after) char *before; /* A pointer to the original string */ char *after; /* A pointer to the reversed string */ { int i; int j; int len; len = strlen (before); for (j = len - 1, i = 0; j >= 0; j--, i++) /* Reverse loop */ after[i] = before[j]; after[len] = NULL; /* NULL terminate reversed string */ } /* REVERSE.H */ void reverse (); /* Declare but do not define this function */ /* MAIN1.C */ #include #include "reverse.h"/* Contains the prototype of reverse () */ main (){ char str [100]; reverse ("cat", str); /* Invoke external function */ printf ("reverse (\"cat\") = %s\n", str); reverse ("noon", str); /* Invoke external function */ printf ("reverse (\"noon\") = %s\n", str); }

cs33208 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. main1 main1.oreverse.o main1.c reverse.h reverse.creverse.h

cs33209 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

cs 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 $<

cs Simplifying Make Files So makefile can be simplified as: $ cat main2.make main2: main2.o reverse.o palindrome.o cc main2.o reverse.o palindrome.o -o main2 main2.o: main2.c palindrome.h reverse.o: reverse.c reverse.h palindrome.o: palindrome.c palindrome.h reverse.h

cs Simplifying Make Files Further simplification (leave out.c files in dependency rules $ cat main2.make1 main2: main2.o reverse.o palindrome.o cc main2.o reverse.o palindrome.o -o main2 main2.o: palindrome.h reverse.o: reverse.h palindrome.o: palindrome.h reverse.h

cs 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

cs 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) –Extract and copy archive content to current directory (x) –Verbose (v) $ ar r string.a reverse.o palindrome.o $ ar t string.a $ ar d string.a reverse.o $ ar q string.a reverse.o $ ar x string.a.

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