/
How do you get a compiler to generate dependency files

How do you get a compiler to generate dependency files

  • 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:

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.

Related content

Make Dependency Files for C/C++ Headers
Make Dependency Files for C/C++ Headers
More like this
C++ Compiler Flags - The Core Ones
C++ Compiler Flags - The Core Ones
More like this
Make recipe rule
Make recipe rule
More like this
Dependency Tree
Dependency Tree
More like this
Simple make system - putting it all together
Simple make system - putting it all together
More like this
Create a command line tool
Create a command line tool
More like this