I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently.
$ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o
$ [ -s foo.d ] && [ -s foo.o ] && echo yay
However, instead of generating
foo.d, I want to generate
foo.D, so I tried:
$ rm foo.d foo.o
$ g++ -std=c++11 -MP -M -MF foo.D -c foo.cxx -o foo.o
$ [ -s foo.D ] && [ -s foo.o ] && echo yay
That successfully generates
foo.D, but makes an empty
foo.o. Why? The documentation for
-MD starts with:
-MD is equivalent to -M -MF file, except that -E is not implied.
Best How To :
I don't know why
-M -MF foo.D isn't working for you my reading of the documentation is the same as yours. I think it should be working. An
strace of the compilation might tell you something interesting about what is going on.
But as a solution you can just add the
-MF foo.D argument to the original command line and that should do what you want.
As the documentation for
-MF file When used with -M or -MM, specifies a file to write the dependencies to. If no -MF switch is given the preprocessor sends the rules to the same place it would have sent preprocessed output
When used with the driver options -MD or -MMD, -MF overrides the default dependency output file.