I apologize if the question is trivial, but I have googled around and downloaded the gcc source code too without finding a satisfactory answer.
So, how the compiler ( gcc/clang/etc... ) knows the file name of the libc? I know that unix-like systems name it libc.a, libc.so, etc... But, for example, mac os x names it libSystem. I suppose the name is hardcoded in the code of the compiler, but I have found no evidence yet.
C Library linkage flag is hard coded in source code of gcc, grep
-lc
or-lSystem
in source code of gcc. On compilation, gcc searchs for libc with namelibc.so
orlibc.a
in its search path ( add prefixlib
and suffix.so
or.a
)Below is some result from
grep '\-lc' -r ./gcc/config/
under gcc source code directory.Result of
grep '\-lSystem' -r ./gcc/config/