Why are there so many header files?
After installing gcc via brew I wanted to find out the location of the header files which gcc uses. I started with stdio.h and looked under /usr/local
I found the following 18 possibilities.
/usr/local/include/c++/11.2.0/tr1/stdio.h
/usr/local/var/homebrew/linked/gcc/include/c++/11.2.0/tr1/stdio.h
/usr/local/var/homebrew/linked/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/var/homebrew/linked/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/opt/gcc@11/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gcc@11/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/opt/gcc@11/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/opt/gfortran/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gfortran/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/opt/gfortran/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/opt/gcc/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/Cellar/gcc/11.2.0/include/c++/11.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
I arranged these into 3 groups which I call
1) the fixed group
/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/opt/gfortran/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/opt/gcc@11/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
/usr/local/var/homebrew/linked/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include-fixed/stdio.h
2) the tr1 group
/usr/local/Cellar/gcc/11.2.0/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gcc/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gfortran/include/c++/11.2.0/tr1/stdio.h
/usr/local/opt/gcc@11/include/c++/11.2.0/tr1/stdio.h
/usr/local/var/homebrew/linked/gcc/include/c++/11.2.0/tr1/stdio.h
/usr/local/include/c++/11.2.0/tr1/stdio.h
and 3) the ssp group
/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/opt/gfortran/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/opt/gcc@11/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
/usr/local/var/homebrew/linked/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0/include/ssp/stdio.h
Then by further experiments I found that, in each group, the version in the Cellar was the real stdio.h file and the remaining 5 versions were links to the Cellar version.
Since the 3 Cellar versions are all different, it turns out that there are 3 different versions of stdio.h under /usr/local.
Running the pre-processor on a .c file showed that C programs compiled with gcc use the fixed version
So this raises two questions:
1) why are there all these links? and
2) what are the tr1 and ssp versions used for?
In addition it turns out that not all header files which gcc uses are under /usr/local. For example, wait.h and signal.h are both in
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys
So why are there header files in /usr/local at all? Do some of the ones in
/Library/Developer/CommandLineTools
not work with gcc?
And by the way there are a lot more stdio.h files on the system than just the ones under /usr/local
There are more that 100 stdio.h files under /Applications/Xcode.app. Probably most are links to some of the others, but I haven't checked that out.
And finally, just for reference, clang gets its stdio.h version from
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
iMac Pro, macOS 11.3