Question

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.)

Was it helpful?

Solution 2

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

OTHER TIPS

Try

%.cpp : h1.h h2.h

That works in GNU make - no idea if nmake is compatible...

Edit: And btw: shouldn't that be

helper.o : dtds.h

%.o :  h1.h h2.h

After all, you don't want to remake the .cpp file (how do you make a source file?), but recompile...

Edit2: Check the NMAKE Reference. According to this, something like

.cpp.obj: h1.h h2.h

might work...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top