Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Solving With C++ Recitation – make February 2016.

Similar presentations


Presentation on theme: "Problem Solving With C++ Recitation – make February 2016."— Presentation transcript:

1 Problem Solving With C++ Recitation – make February 2016

2 Make Utility: The "make" is a utility which automatically determines the pieces of a large program that need to be recompiled, and issues commands to recompile them. Problem: Recompiling the whole project consisting hundreds of files for every minor code changes will take hours. Solution: makefile Syntax: target: [ ] * [ ]

3 Example: exec: movie.o actor.o g++ -Wall –I. movie.o actor.o –o exec movie.o: movie.cpp movie.h g++ -Wall –I. –c movie.cpp actor.o: actor.cpp actor.h g++ -Wall –I. –c actor..cpp Order of Execution If you type make and hit enter, it will look for a make file in the current directory and run the commands of the first target If you type make and hit enter, it will look for a make file in the current directory and locate the target. How does make work: Each file has a timestamp that indicates when the file was last modified make looks at the timestamp of the file, and then the timestamp of the dependencies (which are also files) If the dependencies have changed, then the target needs to be updated. More precisely, if the dependent files have a more recent timestamp than the target, then the command lines are run

4 make all: Sometime we need to create more than one executable. You can achieve this with an all target. Example: all: p1 p2 p3 p1: Foo.o main1.o g++ -Wall –I. Foo.o main1.o -o p1 p2: Bar.o main2.o g++ -Wall –I. Bar.o main2.o -o p2 p3: Baz.o main3.o g++ -Wall –I. Baz.o main3.o -o p3 make clean: To guarantee a most recent rebuild, we have to recompile the entire project. It’s a good idea to clean all the executable files & object files before recompiling. Example: clean: rm *.o p1 p2 p3 make tar: When you submit files, often you have tar many files together. Example: tar tar –cvf assignment1.tar *.cpp *.h p1

5 ASSIGNMENT Download complex example file from cs253 progress page Create a makefile making use of all three different targets(tar,clean,all)


Download ppt "Problem Solving With C++ Recitation – make February 2016."

Similar presentations


Ads by Google