Reputation: 24160
I want to add header file dependency in make file
I written rule
${OBJECTDIR}/%.o: %.cc %.h
gcc $(WarningLevel) $(CFLAGS) $(INCLUDES) -c -o $@ $^
but there are two error
One for .cc file which don't have any .h files . It will give no rule to make. Second one is the object file build by rule give error at linking
file format not recognized; treating as linker script
how can I achieve that ? (source file should be compile if header file is got modified )
Upvotes: 2
Views: 3576
Reputation: 18667
First of all, you haven't shown us your link command. Secondly, you shouldn't be using $^
here. $^
expands to a list of all dependencies (here, the .c
and the .h
), but we only want to compile the .c
file. Use $<
, which expands only to the name of the first dependency:
${OBJECTDIR}/%.o: %.c %.h
gcc $(WarningLevel) $(CFLAGS) $(INCLUDES) -c -o $@ $<
Upvotes: 2
Reputation: 5156
You need to provide a rule for the header file dependency you listed:
%.h:
echo This is my build target for header files.
Make won't actually do anything with the %.h files, but atleast you're telling it to watch for file changes (which then cause the .o files to need recompilation).
Upvotes: 1