It seems the generated auto dependency rules in Eclipse CDT 8.1.0 are incorrect. To illustrate the problem I made an empty Executable project and added two files.
test.cpp:
#include "SomeOtherHeader.h"
int main(void){return 0;}
and SomeOtherHeader.h (which is empty)
Compiling this project causes Eclipse to generate the "Debug" folder in the project directory with the subdir.mk makefile include.
Contents of Debug/subdir.mk:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../test.cpp
OBJS += \
./test.o
CPP_DEPS += \
./test.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
Its the -MT"$(@:%.o=%.d)"
line that concerns me because the MT option creates a nonsensical dependency in the file Debug/test.d
test.d: ../test.cpp ../SomeOtherHeader.h
../SomeOtherHeader.h:
Changing -MT"$(@:%.o=%.d)"
to -MT"$@"
in Debug/subdir.mk yields a more reasonable Debug/test.d:
test.o: ../test.cpp ../SomeOtherHeader.h
../SomeOtherHeader.h:
It looks like the "-MT" string is hard coded in the managedbuilder.core java code:
$ unzip -p /usr/lib64/eclipse/dropins/cdt/eclipse/plugins/org.eclipse.cdt.managedbuilder.core_8.1.0.201206111645.jar | strings | grep '\-MT'
-MT"
-MT"$(@:%.o=%.d)"
-MT"
-MT"$@"
-MT"$(@:%.d=%.o)"
It looks like the winning option -MT"$@"
is in there, but how do I instruct the managedbuilder to use it? Does -MT"$(@:%.o=%.d)"
serve any practical purpose?
Its my first time posting on this site so be easy on me :)
Add -MT"$@"
to compiler flags in Project Properties->C/C++ Buid->Settings->GCC Compiler->Miscellaneous->Other flags
. Eclipse will simply add this flag to compilation line inside makefile. Output inside test.d
file should be something like:
test.o test.d: ../test.cpp ../SomeOtherHeader.h
../SomeOtherHeader.h: