Next Previous Contents

2. Lots of tips

2.1 Automating dependency creation

There is a neat utility called makedepend which can go through your source code and see which files #include which other ones. It then tacks a bunch of dependency lines to the bottom of your makefile with a commented line that says ``Do not delete this line.'' You can use it again later to update those dependency lines. Makedepend is used like this:

makedepend [options] source-files...

For options, -Idirectory tells it to look in directory for include files, and -Ydirectory tells it not to look in directory. Just -Y by itself means not to look at any of the system include directories. You can give as many -I and -Y options as you need. Makedepend can ignore any options it doesn't understand if you put them between double dashes (--); this is useful as you'll see below.

If you give it -Y, it will probably spit out a bunch of stuff about not being able to find iostream.h and so on. Just ignore these messages; they are harmless. Note that you could get rid of them by omitting -Y, but then your makefile would have all sorts of long rules stating that foo.o depends on iostream.h and ios.h and streambuf.h and strbuf.h and .... Since those system header files almost never change, you don't want make to waste time scanning them, so you generally leave in the -Y.

After makedepend scans your source code, it tacks the resulting dependency rules onto the end of your makefile and saves you a ton of typing. It's very useful to have a ``depend'' target in your makefile which does this automatically:

depend:
   ->   makedepend -- $(CXXFLAGS) -- -Y $(SRC_FILES)

We give makedepend the CXXFLAGS because that macro contains the -I commands which are normally passed to g++ to tell it where the various .h files are, but those same commands are useful here. Makedepend happily ignores any other options in CXXFLAGS such as debugging flags because of the double dashes --.

2.2 Troubleshooting

(Problems and suggestions, in increasing order of unlikeliness.)


Next Previous Contents