Sample Header Ad - 728x90

Do C compilers discard unused functions when statically linking to .a file?

39 votes
3 answers
15663 views
Say I have a C program main.c that statically links to libmine.a. Statically linking to a library causes library functions to be embedded into the main executable at compile time. If libmine.a were to feature functions that weren't used by main.c, would the compiler (e.g. GCC) discard these functions? This question is inspired by the "common messaging" that using static libraries make executables larger, so I'm curious if the compiler at least strips away unused code from an archive file.
Asked by Izzo (1013 rep)
Sep 2, 2022, 12:14 PM
Last activity: Sep 3, 2022, 01:48 PM