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

Posted on Oct 30, 2021 1:28 PM

Reply

Similar questions

2 replies

Oct 30, 2021 2:28 PM in response to rkg1945

rkg1945 wrote:

So why are there header files in /usr/local at all? Do some of the ones in

/Library/Developer/CommandLineTools

not work with gcc? 

The sam reason why no one here is going to comment on gcc. GCC has its own compiler and doesn't want to have any dependencies on whatever Apple might, or might not, have installed in various system directories.


If you are curious about why GCC does thinks a certain way, you will have to track them down where they live. These forums are user-to-user support forums for Apple products. It would be very unusual to find any Apple user who does anything with GCC. That ship has sailed. We are on clang now.

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.

I really only see 3 per platform. There is a "_stdio.h" and a "sys/stdio.h" for each platform. But even if I include those, that is only about 6 per platform for a total of 51.

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

Well, it's complicated. The Command Line tools are for people who just want to build something on their Mac. I wouldn't recommend installing both the Command Line tools and Xcode. Xcode can certainly do everything the Command Line tools can, but a lot more. But generally, Xcode users rarely target their own platform. They are normally building for iPhone, Watch, etc. Anything that just happens to find some include file in /usr/include is going to really ruin your day in that case.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why are there so many header files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.