next up previous contents
Next: Preparing the Makefile: Up: Performance Enhancing Tools Previous: Performance Enhancing Tools

Handling your Programs Efficiently: The Make Utility:

As long as you are working with one C source file say prog.c you will typically use the following command to compile cc prog.c -o prog -lm. When you work with multiple files i.e your total program is split in more then one file, you need a compilation or a linking procedure which is not cumbersome. Here's why. Say you have two files main.c and average.c. There are some functions in the average.c that you access in main.c. You will first compile main.c to obtain an object file cc -c main.c (note the -c option creates the object file only)

At this time if you do a ls you will notice main.o in the directory along with the other files. Similarly obtain average.o. Now you need to link them to obtain the final executable because in .o files external linkages are not resolved. cc -o average main.o average.o
Now if there is a change in main.c or object.c you will again have to go through the procedure of obtaining the object file and then linking it with the others. Imagine doing this for 5 files out of the 10 you worked on.

The make utility helps in situations like above. First a special file is created called the Makefile (note the capital M) and kept in the same directory as all other files, .c and .o . Once we create this file by a procedure described next, we type make at the command line. The make program will read the compilation and linking instructions in the Makefile and create the executable thus saving time for the programmer.





Sushil Prasad
Fri Oct 9 10:28:36 EDT 1998