Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:

Slides:



Advertisements
Similar presentations
CSE 303 Lecture 16 Multi-file (larger) programs
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.
Makefiles Tutorial adapted from and myMakeTutorial.txt.
1 The Makefile Utility ABC – Chapter 11,
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Lecture 2: Miscellaneous UNIX/C concepts –Key based authentication and remote shell –Portable C programs and C standards –Debugger –Make –Some commonly.
Guide To UNIX Using Linux Third Edition
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.
CSE : Programming in C Instructor: Lei Wang Office: Dreese Lab 474 Office Hour: Friday.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Dr. T. Doom Lab.1 CEG 433/633 - Operating Systems I OS Course Assignments Lecture foils are available on-line:
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
C Tutorial - Program Organization CS Introduction to Operating Systems.
Makefile M.A Doman. Compiling multiple objects Card.cpp -> Card.o Deck.cpp -> Deck.o main.cpp -> main.o main.o Deck.o Card.o -> Dealer.exe.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
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.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
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.
Introduction to Systems Programming (CS 0449) C Preprocessing Makefile File I/O.
Data Display Debugger (DDD)
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
CMSC 1041 Introduction to C Creating your first C program.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 9 Acknowledgements: The syllabus and power point presentations are modified versions.
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.
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?
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Adv. UNIX:pre/111 Advanced UNIX v Objectives of these slides: –look at the features of the C preprocessor Special Topics in Comp. Eng.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
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.
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
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.
系統程式 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
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.
Makefiles Caryl Rahn.
Advanced UNIX progamming
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.
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Makefiles and the make utility
Unix Programming Environment
Creating your first C program
CMPSC 60: Week 4 Discussion
Appendix F C Programming Environment on UNIX Systems
Video Notes.
Makefiles and the make utility
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
SPL – PS1 Introduction to C++.
Presentation transcript:

Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site: Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

Announcements Collected your quizzes –The grade on this will not count towards your course grade –However, it will provide you feedback on your C knowledge –You can try the linked list question at home You should be able to write the code within 15 minutes, without referring to any book You should have received an from me, if you are registered for this course

Week 1 Topics Course outline and policies UNIX programming environmentUNIX programming environment –Editors –C compilers and debuggers –Makefiles Review some features of CReview some features of C –Header files –Command line arguments –Utilities Review some UNIX system calls –system, etc

UNIX programming environment EditorsEditors C compilersC compilers DebuggerDebugger MakefilesMakefiles –make

vi, pico, emacs, etc What is good about emacs? –emacs is more than just an editor –You can compile and edit within emacs –If you know lisp, you can expand its functionality –Some useful commands to get started: C-h t get tutorial C-g cancel command C-x C-c quit emacs C-h help Editors

etags This helps you go to a function definition –Particularly useful in programs spanning multiple files –At the shell prompt, type etags *.[ch] –In emacs Choose visit tags from the _C_ menu –Or ESC-x visit-tags-table Subsequently, find tag from the menu, or ESC-., will take you to the function definition

Compiling in emacs Choose compile from the _C_ menu –Or ESC-x compile –Errors and warnings will be printed on a sub-window –CTL-X ` will take you to the next error or warning

gcc, cc Using ANSI C, the code must pass with flags –Wall –ansi –pedantic with no warning messages See example1.cexample1.c –How can we fix warning? Some examples –gcc –g –Wall –ansi –pedantic example1.c –gcc –g –c –Wall –ansi –pedantic example1.c –gcc –g example1.o –gcc –g example.o -lm C compilers

ddd, xxgdb, gdb The code must be compiled with –g option. The power of a debugger: –Finding the line that causes core dump –See example1.c Break point, show value, change value, step, next, continue, print –Very efficient in debugging sequential code –Not very effective in debugging concurrent code (multiple threads, multiple processes) Good software development practice: You must have seen each line of your code execute in the debugger, at least once Debugger

run to run the program

make [-f makefile][option] target –A tool to update files derived from other files –The default files for make are./makefile,./Makefile,./s.makefile –Use the –f option to specify some other file make –f makefile1 –The makefile has three components Macros: define constants Target rules: Specify how targets are made Inference rules: Specify how targets can be made, implicitly. make will first check if a target rule applies, before using inference rules. Make

Macros: String1 = string2. –Example CC=gcc CFLAG=-Wall –ansi –pedantic Target rules: Target : [prerequisite…] command –Example a.out : myprog1.c myprog2.c myprog3.c $(CC) $(CFLAG) myprog1.c myprog2.c myprog3.c make... continued

Inference rules Target: command Target must be of the form.s1 or.s1.s2 where.s1 and.s2 must be prerequisites of the.SUFFIXES special target. –.s1.s2  make *.s2 from *.s1 –.s1  make * from *.s1 Example:. c: $(CC) –o $<.c.o: $(CC) –c $< make... continued

See the example makefiles –makefile, makefile1, makefile2makefilemakefile1makefile2 makefile1 will recompile only the modified files, instead of everythingmakefile1 makefile2 has inference rulesmakefile2 can be used to find more informationwww.cs.fsu.edu/cgi-bin/man.cgi makefile examples

Review some features of C Header filesHeader files MacrosMacros Command line arguments Utilities

Header files Usually define interfaces between separately compiled modules May contain macro definitions, preprocessor directives, declarations of types, and function prototypes Should not contain variable definitions or executable code

Some header file errors Improper header file use can cause problems –Try compiling example2.c –Including a header file multiple times may cause redefinition errors –Why does including stdio.h twice not cause any problem? Look at /usr/include/stdio.h

Conditional Code in Headers Preprocessor directives are used to prevent the body of a header file from being used multiple times. #ifndef MYHEADER #define MYHEADER /* the body of the header file */ #endif

Macros with and without Parameters #define MAX_LENGTH 256 –... for (i = 0; i < MAX_LENGTH; i++)... Macros can have parameters –#define max(a,b) (a > b) ? a : b What is wrong with the following? –#define sum(a, b) a + b –#define product(a, b) a*b –See example3.c, example3b.c, example3c.c, and example3d.c