CSC 201 Grinnell College Spring, 2005
 
Data Representation, Memory Management, and Formal Methods
 

Practice with Separate Compilation and Makefiles

Goals: This lab provides practice dividing a program into pieces, compiling those pieces separately, linking components together to form an executable, and automating this process using the Unix utilities make and Makefile.

Reference: The main reference for this lab is:

Steps for this Lab: Using the discussion of trees in the Program Management material above as an example, consider the two linked list labs that appeared earlier this semester. Specifically, Lab 5 introduced singly linked lists, while Lab 6 added functionality for this work.

  1. Copy your finished program for labs 5 and 6 to a new file lists-divided.c.

  2. Divide this program into the following pieces, with the given file names:

    Thus, the node and list prototypes will each have their own files, each operation will have its own implementation file, and the main program will have another implementation file.

  3. Using script to record your work, compile each of the implementation files using a relevant gcc command, and then link all of the files together using gcc. Run the resulting program to show that the various compiling and linking options have worked appropriately.

  4. Write a Makefile to automate the process of compiling and linking.

  5. Run the make command for each of the following cases.
    1. Test Makefile for compiling the entire program.
      (You will have to delete all .o files first.)
    2. Make a change in list-print.c, perhaps changing the message printed at the beginning or the end of the list. Then run make and describe which files are compiled and linked.
    3. Make a change in list-proc.h.c, adding only a comment to the start of the file. Again, run make and describe which files are compiled and linked.

Work to turn in:


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/201.sp05/lab-prog-mgmt.html

created 3 December 2001
last revised 2 May 2005
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.