Where is my "stdio.h" on Mac?

I know Mac OS X is a Unix based system. And I heard that this standard C library, such as stdio.h, is in /usr/local/include or /usr/include . But there is no library in this directory. I use Terminal to search this directory, and I also use a command like find ./ -iname "stdio.h" , but nothing comes of it. However, oddly enough, the gcc -test.c -o test command works. How did this happen? I want to know where my C. library is located. Ps I also use Xcode. Is this related to this app? Help me! And I have an AWS EC2 linux server, and it has both libraries that I referenced above.

+18
c macos
source share
8 answers

If you have Xcode, but the optional command-line toolkit is not installed, then the standard includes and libraries cannot be found in the usual place. Try:

 $ find /Applications/Xcode.app -name stdio.h 

and you will probably see something like:

 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/tr1/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/4.2.1/tr1/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sys/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/tr1/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/sys/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1/tr1/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h 

However, you might want to install the command-line tool package if you plan to do any programming without Xcode (for example, the command line) . Then you will see the usual headers and libraries in /usr/include and /usr/lib .

+28
source share

If you do not have the command line tools installed, you can run:

 xcode-select --install 

A dialog box opens allowing you to accept the license agreement, etc.

(This was not in the answers above.)

+24
source share

create / update a symbolic link for /usr/include to detect files:

 sudo ln -sf /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /usr/include 

The specified path can be found by searching stdio.h

 find /Applications/Xcode.app -path '*/usr/include/stdio.h' 

I need to do this with every Xcode / MacOS SDK update, today it happened with the Xcode 7 update.

After installing the command line tools, they cannot be reinstalled using xcode-select , so the path may not be updated when updating the Mac App Store.

Uninstalling and reinstalling xcode-select --install and then running xcode-select --install may update the path, but this is overkill.

Some posts also mention xcode-select --switch /Application/Xcode.app , but I'm out of luck with it.

+8
source share

The main reason is the lack of the / usr / include folder; installing command-line tools sometimes does not automatically add it.

Install package on

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

+4
source share

On my laptop, it appears in many places, such as /usr/include/stdio.h and /usr/include/sys/stdio.h and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h .

+2
source share

If you have already created your location database, you can use

 locate stdio.h 

If you have not already done so, create one. The locate team is awesome !

+1
source share

In the folder

 Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include 

or similar.

0
source share

I installed "CommandLineTools" and the file "stdio.h" exists in the Xcode and CommandLineTools directories.

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include /stdio.h

0
source share

All Articles