Section: Archives and libraries

Build static library

makefile
makefile
libfoo.a: $(OBJ)
	ar rcs $@ $^
Explanation

Common for C/C++ libraries.

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 Archives and libraries
Update archive with newer objects
Use `$?` to add only changed prerequisites.
OpenIn sheetmakefilesame section
Basic pattern rule
Compile any `.c` file into a matching `.o` file.
OpenIn sheetmakefile
$@ target name
Expand to the current target file.
OpenIn sheetmakefile
wildcard function
Expand glob patterns during parsing.
OpenIn sheetmakefile
Generate C header dependency files
Have the compiler emit `.d` files while building objects.
OpenIn sheetmakefile
Pattern rule with directories
Build objects into a separate output directory.
OpenIn sheetmakefile