A lot of non related libraries gets defined... audio/lewton: Libs.private: -lexecinfo -lpthread -lgcc_s -lc -lm -lrt -lpthread -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat graphics/libimagequant: Libs.private: -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat -lexecinfo -lpthread -lgcc_s -lc -lm -lrt -lpthread -lrt -lutil -lexecinfo -lkvm -lmemstat -lkvm -lutil -lprocstat -lrt -ldevstat etc
Looking this seems to "leak" from libc crate?
Only -lgcc_s (see upstream issue) breaks static linking. $ cc a.c -static $(pkg-config -static --cflags --libs imagequant | sed 's/gcc_s/gcc/') $ file ./a.out ./a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, for FreeBSD 14.0 (1400085), FreeBSD-style, with debug_info, not stripped $ cat a.c #include <libimagequant.h> int main() { (void)liq_attr_create(); return 0; }
Overlinking isn't a problem with static libraries as ld(1) only includes object files (*.o) from archives (*.a) that satisfy references. However, object files can be large, so one may want to pass -Wl,--gc-section to trim unused stuff.
Note, to overlink a static library pass -Wl,--whole-archive