Libc name and compilers

93 views Asked by At

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.

1

There are 1 answers

0
D3Hunter On

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 name libc.so or libc.a in its search path ( add prefix lib and suffix .so or .a)

Below is some result from grep '\-lc' -r ./gcc/config/ under gcc source code directory.

......
./gcc/config/i386/sysv5.h:  %{!shared:%{!symbolic:-lc -lcrt}}"

Result of grep '\-lSystem' -r ./gcc/config/

./gcc/config/darwin.h:#define LIB_SPEC "%{!static:-lSystem}"