The issue is that make command cannot detect changes in head file. i.e, if I touch "test.h", make command will not recompile. This works with gcc 4.5.4 on the same OS. --test.h-- #include <iostream> void hello() { std::cout << "Hello\n"; } --test.cc-- #include "test.h" int main() { hello(); } --Makefile-- sources := test.cc objects := test.o depends := test.d main := test $(main) : % : %.o g++ $< -o $@ %.o : %.cc g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" $< -o $@ clean : -rm -rf $(objects) $(depends) $(main) ifneq ($(MAKECMDGOALS),clean) -include $(depends) endif
-MT changes the target to the .d rather than adding it to the .o one.
This was an expected change, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12448 . Which says you need another -MT option to include the .o target.
I am a little confused. -MT will create .d file. Then make command will include .d and re-compile if dependency file changes. The issue is that g++ 4.6.1 doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If I need another -MT, what syntax it should be? Thanks a lot! (In reply to comment #2) > This was an expected change, see > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12448 . Which says you need > another -MT option to include the .o target.
(In reply to comment #3) > I am a little confused. -MT will create .d file. Then make command will include > .d and re-compile if dependency file changes. The issue is that g++ 4.6.1 > doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If Did you read the linked bug report? Did you look at the content of test.d? > I need another -MT, what syntax it should be? Thanks a lot! g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" "-MT$@" $< -o $@
This did solve the issue. Thanks a lot for the explain and syntax! (In reply to comment #4) > (In reply to comment #3) > > I am a little confused. -MT will create .d file. Then make command will include > > .d and re-compile if dependency file changes. The issue is that g++ 4.6.1 > > doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If > > Did you read the linked bug report? Did you look at the content of test.d? > > > I need another -MT, what syntax it should be? Thanks a lot! > > g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" "-MT$@" $< -o $@