+ All Categories
Home > Documents > MAKEFILES A description file that defines the relationships or dependencies between applications and...

MAKEFILES A description file that defines the relationships or dependencies between applications and...

Date post: 19-Dec-2015
Category:
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
14
Transcript

MAKEFILESMAKEFILES

A description file that defines the relationships or dependencies between applications and functions; it simplifies the development process by automatically performing tasks necessary to rebuild an application when you modify code.*

*: http://www.ssec.wisc.edu/mcidas/doc/prog_man/2003/glossary.html#16906

CPP & Header FilesCPP & Header FilesYou would have to compile each of these files separately to produce .o files and then link them all together. The following commands show how to do this. Notice the -c option you need to specify when you want to compile only , not to compile and link.

Time Consuming…Time Consuming…

Compile only: g++ -c main.cpp

Compile only: g++ -c myfunction.cpp

Link: g++  main.o   myfunction.o  -o main

Note that if you wanted to compile a whole set of C++ programs at the same time, you could enter: g++ -c *.cpp

Be careful with this though, for these reasons:

- Using the wildcard "*" will refer to every .cpp file in the current directory. If you are going to use this, you should first put all the files for the program in a special directory for that program.

- If you have only made a change to one file, there is no reason to compile every single file. In a program that consists of many files, this is extremely time-consuming.

Compiling & LinkingCompiling & Linking

Note that to link a whole set of object files you could have just entered: g++   *.o   -o main

Again, you should be careful that you have all your files in one directory. The following diagram illustrates how the previous example appears conceptually:

Without Makefile scenerioWithout Makefile scenerio

> g++ -c Calculatr.cpp

> g++ -c DoMenu.cpp

> g++ -c GetOperands.cpp

> g++ -c AddNums.cpp

> g++ -c ModNums.cpp

> g++ -c Expon.cpp > g++ Calculatr.o DoMenu.o GetOperands.o AddNums.o ModNums.o Expon.o -o Calculatr

Either recompile all (TIME CONSUMING)

OR

Just those are changed & their dependents

(THIS ALSO TAKES YOUR TIME)

Inside of a Makefile FileInside of a Makefile File

How to Use It: How to Use It: simply enter simply enter make make targettarget at at the system promptthe system prompt


Recommended