Simply pass -Wl,--exclude-libs,ALL
to gcc
This will tell the linker to transform all the symbols in the static libraries to hidden.
--exclude-libs
also accepts a list of archives (i.e. static library names) for finer granularity on which libraries to hide symbols from.
Note: this will only work in systems using GNU binutils (e.g. Linux) or with a linker supporting --exclude-libs
(e.g. it won’t work with OSX’s ld64)