InsaneCoder
InsaneCoder

Reputation: 8278

Compilation order and compilation dependencies

Suppose I have a C program separated into several smaller files and include each other as follows :

Taken from http://www.cs.cf.ac.uk/Dave/C/node3.html

Now I have the following queries as to what extent I am correct. Please correct me wherever I am wrong:

1. Which files have to recompiled after I make changes to process1.c?

main.c ?

2. Which files have to recompiled after I make changes to process1.h?

main.c and process1.c?

3. Which files have to recompiled after I make changes to list.h? 

input.c and process2.c?

Upvotes: 2

Views: 71

Answers (3)

too honest for this site
too honest for this site

Reputation: 12263

Simply put:

A file has to be recompiled if any of the files it depends on has been changed.

Note that this is recursive, so if any of the object files has changed because they have been recompiled, the program file (which normally depends on all object files) has to be re-built (i.e. linked, not compiled), too.

You might try SCons as an easier and more powerful alternative to good ol' make.

Upvotes: 0

David Grayson
David Grayson

Reputation: 87446

This is really easy. If X gets changed, any .c file that includes X (or is X) needs to get recompiled. The answers are:

  1. process1.c
  2. process1.c, main.c
  3. process2.c, input.c

Upvotes: 3

alifirat
alifirat

Reputation: 2937

I think the best answer to your question is to write a Makefile and then to check which files are compiled after changing one like your question.

Upvotes: 0

Related Questions