The framework supports building static archives (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fernandodanielmaqueda/gcc-bison-flex-GNUmakefile/llms.txt
Use this file to discover all available pages before exploring further.
.a) and shared libraries (.so) alongside programs in the same GNUmakefile. This is useful for extracting reusable logic into a library, sharing code across multiple programs in the same repository, or producing a distributable library as the primary build output.
When to build libraries
Build a static library when you want to link a module directly into your final binary — the library code becomes part of the executable. Build a shared library when multiple programs should share the same compiled code at runtime, or when you are producing a.so for distribution.
Declaring libraries
Static library
Add the library filename (including thelib prefix and .a extension) to BIN_LIBRARIES:
Shared library
Add the filename toBIN_SOLIBRARIES:
The
-fpic flag is added automatically for every shared library declared in BIN_SOLIBRARIES. You do not need to add it yourself to _CFLAGS.BIN_LIBRARIES and BIN_SOLIBRARIES use the same BIN prefix as BIN_PROGRAMS. Output files are placed in BINDIR (default: bin/).
Required declarations per library
Libraries need_SOURCES just like programs do. Static libraries do not use _LDADD — only programs and shared libraries require a linking order. For a shared library, set _LDADD the same way you would for a program.
How AR and RANLIB work for static libraries
When building a static library, the framework runs:ARFLAGS default is -r -v: -r inserts or replaces members, -v prints the member names as they are processed.
After ar, the framework checks for ranlib at runtime. ranlib is a dispensable command — if it is not found, the build continues without it. When found, it runs:
RANLIB variable to point to a different indexer or clear it to skip the check entirely.
.SECONDARY and the -t option
When Make’s-t (touch) option is active, the framework uses a lighter-weight path for static libraries: it touches the archive file and runs ranlib -t (which updates the timestamp without reindexing), suppressing any errors that ranlib -t might produce on non-archive files:
Linking a library into a program
Static library
Add the library to the program’s_LDADD in the correct link order (the program’s object files before the library):
_LDFLAGS at the directory containing the library if it is not in a location the linker searches by default. The _FIND_-L_FLAGS mechanism can discover lib*.a and lib*.so files automatically:
-L flag:
-l flag in _LDADD:
Shared library
Shared libraries are linked the same way. At runtime the program must be able to find the.so, either via LD_LIBRARY_PATH or by installing it to a standard location. You can also embed a runtime search path with -Wl,-rpath.
Complete example: static library
This example buildslibcalc.a from src/calc.c and links it into myprogram.
Project layout:
Build the library and the program
bin/libcalc.a first (because myprogram depends on it via _LDADD), then links bin/myprogram.Complete example: shared library
The framework passes
-shared -Wl,-soname,'libcalc.so' to the linker automatically when building a shared library declared in BIN_SOLIBRARIES. You do not need to add these flags yourself.Next steps
Multi-program project
Build multiple programs and libraries in one GNUmakefile.
Programs and libraries reference
Full variable reference for BIN_PROGRAMS, BIN_LIBRARIES, and BIN_SOLIBRARIES.
Build targets
All available make targets for building.
Pure C project
Start with the simplest single-program setup.