Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  • How can we generate dependency files?

  • G++ and llvm support the -MMD compiler flag.

More Detail

Let’s say we used the -MMD flag for a C++ file called main.cpp. Then it might look like this:

Code Block
main.o: main.cpp ../CMD/CMDlineParser.h ../COL/COLlog.h \
  ../COL/COLostream.h ../COL/COLstring.h ../COL/COLminimumInclude.h \
  ../FIL/FILutils.h ../COL/COLauto.h ../COL/COLerror.h \
  ../COL/COLrefCounted.h ../COL/COLsinkString.h ../COL/COLsink.h \
  ../COL/COLclosure.h ../COL/COLlist.h ../SCK/SCKloop.h \
  ../SCK/SCKsystem.h ../SCK/SCKschedule.h ../COL/COLmap.h \
  ../COL/COLpair.h ../COL/COLhashmap.h ../COL/COLhash.h \
  ../COL/COLdateTime.h ../SCK/SCKnameResolver.h ../SCK/SCKaddress.h \
  ../COL/COLthread.h ../COL/COLthreadQueue.h ../COL/COLqueue.h \
  ../COL/COLlocker.h ../COL/COLmutex.h ../WEB/WEBserver.h \
  ../SCK/SCKlistener.h ../SCKS/SCKSsslContext.h ../COL/COLvector.h \
  ../COL/COLweb.h ../COL/COLvar.h ../WEB/WEBsession.h \
  ../WEB/WEBrequestData.h ../WEB/WEBmainThread.h ../WEB/WEBresponse.h \
  ../WEBI/WEBImimeLookup.h ../COL/COLthreadPool.h ../SCK/SCKutils.h                                                                      

This is the list of header files that if one of these changes, the main.cpp file should be recompiled.

The compiler invokes the C Preprocessor which recursively resolves the list of all the header files. Keep in mind often header files include other header files so this list can get quite large.