All .cpp files depend on two .h files?

In the makefile, I have the following line:

helper.cpp: dtds.h

      

This will ensure that helper.cpp is restored when dtds.h changes. However, I want ALL files in the project to be rebuilt if one of the other two header files changes, like this:

*.cpp: h1.h h2.h

      

Obviously this won't work, but I don't know how to properly get nmake to do what I want. Can anyone please help? I don't want to manually specify that every single file depends on h1.h and h2.h.

Thank. (I am using nmake included in visual studio 2005.)

+1


source to share


2 answers


Thanks for your help Christophe. I tried:

.cpp.obj: h1.h h2.h

      

And got a helpful error message:



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

      

I solved this by making a list of the files that I wanted to compile and then adding the dependency to the entire list.

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

+1


source


Try

%.cpp : h1.h h2.h

      

This works in GNU make - don't know if nmake is compatible ...

Edit: And btw: shouldn't be

helper.o : dtds.h

%.o :  h1.h h2.h

      



After all, you don't want to remake the file .cpp

(how to create the original file?), But recompile ...

Edit2: Check NMAKE Help . According to this , something like

.cpp.obj: h1.h h2.h

      

can work...

+3


source







All Articles