Search code examples
makefilenmake

All .cpp files depend on two .h files?


In a makefile, I have the following line:

helper.cpp: dtds.h

Which ensures that helper.cpp is rebuilt whenever dtds.h is changed. However, I want ALL files in the project to be rebuilt if either of two other header files change, kind like this:

*.cpp: h1.h h2.h

Obviously that won't work, but I don't know the right way to get nmake to do what I want. Can someone help? I don't want to have to manually specify that each individual file depends on h1.h and h2.h.

Thanks. (I'm using nmake included with visual studio 2005.)


Solution

  • Thanks for your help, Christoph. I tried:

    .cpp.obj: h1.h h2.h
    

    And got the helpful error message:

    makefile(58) : fatal error U1086: inference rule cannot have dependents
    

    I ended up solving it by making a list of the files that I wanted to compile, and then adding the dependency to the whole list.

    files = file1.obj file2.obj file3.obj
    $(files): h1.h h2.h