3

I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently.

This works:

$ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o
$ [ -s foo.d ] && [ -s foo.o ] && echo yay
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.

4
  • 1
    Have you tried just adding -MF foo.D to the original call? Commented Jun 18, 2015 at 14:49
  • @EtanReisner Nope! Guess that's the answer :) Didn't think of that for some reason. Commented Jun 18, 2015 at 14:54
  • @EtanReisner Want to post that as an answer so I can accept it? Commented Jun 18, 2015 at 15:20
  • The docs for -MF explicitly mention it that's why I suggested it. I'm not sure why -M -MF doesn't work though. That strikes me as odd. Commented Jun 18, 2015 at 16:09

1 Answer 1

2

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.