Sunday 20 November 2011

My program has several files in it. How do I keep them all straight? in C programming

My program has several files in it. How do I keep them all straight?

Your compiler includes a MAKE utility (typically called MAKE.EXE, NMAKE.EXE, or something similar)that is used to keep track of projects and the dependencies of source files that make up those projects. Here
is an example of a typical MAKE file:
myapp.obj: myapp.c myapp.h
cl -c myapp.c
utility.obj: utility.c myapp.h
cl -c utility.c
myapp.exe: myapp.obj utility.obj
cl myapp.obj utility.obj
This example shows that myapp.obj is dependent on myapp.c and myapp.h. Similarly, utility.obj is dependent on utility.c and myapp.h, and myapp.exe is dependent on myapp.obj and utility.obj. Below each dependency line, the compiler command to recompile or relink the dependent object is included. For instance, myapp.obj is re-created by invoking the following command line:
cl -c myapp.c

In the preceding example, myapp.obj is recompiled only if myapp.c or myapp.h has a time stamp later than myapp.obj’s time stamp. Similarly, utility.obj is recompiled only when utility.c or myapp.h has a time stamp later than utility.obj’s time stamp. The myapp.exe program is relinked only when myapp.obj or utility.obj has a later time stamp than myapp.exe.

MAKE files are extremely handy for handling large projects with many source file dependencies. MAKE utilities and their associated commands and implementations vary from compiler to compiler—see your compiler’s documentation for instructions on how to use your MAKE utility.

Most of today’s compilers come with an integrated development environment, in which you can use project files to keep track of several source files in your application. Having an integrated development environment frees you from having to know the intricacies of a MAKE utility and enables you to easily manage the source files in your project. The integrated development environment automatically keeps track of all dependencies for you.

Cross Reference:

XVIII.1: Should my program be written in one source file or several source files?

No comments:

Post a Comment