Write depfiles beside objects using explicit flags.
Section: Generated dependency files
Separate dependency file path
makefile
makefile
build/%.o: src/%.c
cc -MMD -MP -MF build/$*.d -c $< -o $@Explanation
Useful when object and source directories differ.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Generated dependency files
Generate C header dependency files
Have the compiler emit `.d` files while building objects.
Include generated files safely
Load dependency files only if they exist.