Agenda Make Utility Command Line Arguments in Unix

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

C Language.
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.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 CSC103: Introduction to Computer and Programming Lecture No 26.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
chap13 Chapter 13 Programming in the Large.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction 14.2Redirecting Input/Output on UNIX and DOS Systems.
Command Line Arguments plus Variable-Length Arrays Systems Programming.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
CS 213 Fall 1998 Namespaces Inline functions Preprocessing Compiling Name mangling Linking.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
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.
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
CS-1030 Dr. Mark L. Hornick 1 Java Review Interactive.
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
Data Display Debugger (DDD)
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
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 all linked.
C++ Functions A bit of review (things we’ve covered so far)
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Chapter Topics The Basics of a C++ Program Data Types
The Machine Model Memory
5.13 Recursion Recursive functions Functions that call themselves
A bit of C programming Lecture 3 Uli Raich.
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Strings (part 2) Dr. Xiao Qin Auburn.
CISC105 – General Computer Science
Makefiles.
Basic Elements of C++.
Command Line Arguments
Command line arguments
Command Line Arguments
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.
Objectives Identify the built-in data types in C++
Command Line Arguments
CSE 303 Concepts and Tools for Software Development
Windows Programming Lecture 07
Introduction to C++.
Arrays Part-1 Armen Keshishian.
Command-Line Arguments
Multi-dimensional Array
CS 201 A Whirlwind Tour of C Programming
C++ Arrays.
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Basic Elements of C++ Chapter 2.
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
Makefiles and the make utility
Chapter 14 - Advanced C Topics
Command Line Parameters
Strings and Pointer Arrays
Appendix F C Programming Environment on UNIX Systems
Homework K&R chapter 4.
Makefiles and the make utility
Functions Reasons Concepts Passing arguments to a function
Compiler vs linker The compiler translates one .c file into a .o file
Quick Review EECS May 2019.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Makefile Assignment Create a file called f1.cpp. It should contain the following function: int squareIt ( int x ) { //insert code to calc and return the.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
SPL – PS1 Introduction to C++.
Presentation transcript:

Agenda Make Utility Command Line Arguments in Unix Individual Assignment – 8-Puzzle

Separate Compilation using ‘make’ Two processes occur when we compile a program: 1) Source code is compiled into an object file. 2) Object file is linked to form a load module or executable file.

Compilation g++ -Wall -c myfile.cc 2) Translates source code into machine readable code. 3) References to externally defined functions and/or variables are incomplete.

Linking g++ -o myfile myfile.o Resolves external references left hanging at compilation time. Creates a monolithic executable file.

Separate Compilation This is the process of – 1) Compiling a set of object files, individually. (multiple steps) 2) Then, linking those object files into an executable file. (one step)

Need of Separate Compilation When working on a substantial programming project, we want to use separate compilation because: 1) Entire program not compiled after only one small change, i.e. faster. 2) Team members can compile parts of a program (obj files) to be collected and linked later. 3) The "make" program will "make" life easy!!! (once its set up)

Sample Makefile CC = g++ BFILES = insertion.o insertionf.o insertion : $(BFILES) $(CC) -o insertion $(BFILES) insertion.o: insertion.cpp insertion.h $(CC) -c insertion.cpp

Sample Makefile […contd] insertionf.o: insertionf.cpp insertion.h $(CC) -c insertionf.cpp clean: rm *.o rm insertion

Terms and Definitions CC = g++  Macro Definition BFILES = insertion.o insertionf.o  Macro Definition insertion : $(BFILES)  Macro Expansion $(CC) -o insertion $(BFILES)  Macro Definition insertion.o: insertion.cpp insertion.h $(CC) -c insertion.cpp  Macro Definition

Command Line Arguments in Unix/C++ Say you have a program to calculate the average of input values. (avgPrgm) It looks better to invoke the program as follows $ avgPrgm 5 56 7 3 17 …… rather than asking the user to first enter the number of values that he/she wants to find the average of.

Use of argv and argc A program that does: A program that does not allow the use of command line arguments: Main() { //Statements } A program that does: Main(int argc, char* argv[])

Use of argv and argc [….Contd] argc: a count of number of arguments provided on the command line. argv[]: a vector (array) of pointers to char (strings) representing the command line elements.

Use of argv and argc [Example] Suppose main is the main program in command.cc and it is compiled and run with the following: 38%g++ command.cc –o command 39%command foo bar baz

Eaxmple […contd] …..then when main begins argv and argc are as follows: 4 argc argv f o \0 c m a n d b r

An Example Using argv and argc //Demonstrate the use of argv and argc # include <iostream.h> main(int argc, char *argv[]) { int i; cout<<“The number of elements on the command line:” <<argc<<endl; cout<<“The name of the program:<<argv[0]<<endl; for (i=1; i<argc; i++) cout<<“Command line argument number”<<i<<“:”<<arg[i]<<endl; }

Eaxmple […contd] 38% g++ cmdline.cc –o cmdline 39% cmdline foo bar baz The number of elements on command line:4 The name of the program:cmdline Command line argument number1:foo Command line argument number2:bar Command line argument number3:baz 40%

An Equivalent Usage Since: 1) argv[] is of type char* 2) and since arrays in C/C++ are pointers, then: argv is of type char ** Therefore, void main::process(int argc, char *argv[]) is equivalent to void main::process(int argc, char **argv) Note that following is an optimization: void main::process(int argc, const char **argv)