Compile any `.c` file into a matching `.o` file.
Section: Implicit and pattern rules
Basic pattern rule
makefile
makefile
%.o: %.c
cc -c $< -o $@Explanation
Pattern rules replace many repetitive file-specific rules.
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 Implicit and pattern rules
Pattern rule with directories
Build objects into a separate output directory.
Link binary from generated object list
Assemble final executable from all objects.
Clear built-in suffix rules
Reduce surprises by disabling legacy suffix rules.
Generate C header dependency files
Have the compiler emit `.d` files while building objects.