Create an archive from object files.
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.
Generate C header dependency files
Have the compiler emit `.d` files while building objects.