I know that Mac OS X is a Unix-based system. And I heard that C standard library such as stdio.h, is located in /usr/local/include
or /usr/include
. But there is not any kind of library in this directory. I use Terminal to search this directory and I also use command like find ./ -iname "stdio.h"
, but nothing comes out. However, strangely enough, gcc -test.c -o test
command works out. How did it happen? I want to know where my C library is located.
p.s I also use Xcode, too. Is it related with this application? help me!
And I have AWS EC2 linux server, and it has both libraries that i refereed above.
10 Answers
If you have Xcode but have not installed the optional Command Line Tools package then the standard includes and libraries may not be found in the usual place. Try:
$ find /Applications/Xcode.app -name stdio.h
and you'll 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 Tools package if you plan on doing any non-Xcode (i.e. command line) programming. You will then see the usual headers and libraries in /usr/include
and /usr/lib
.
-
Thanks. But after i installed command line tools, only /usr/include have library file. there is no "/usr/local/include" !! which means, when i type "cd /usr/local/include", error comes out : No such file or directory. is it ok ?? Feb 6, 2015 at 10:17
-
1@user3595632 That's fine,
/usr/local
is traditionally used by add-on SDKs and packages, not by the platform vendor. Feb 6, 2015 at 10:22 -
1That's right - /usr/local is for installing third party stuff so that it doesn't get overwritten when you update the system. System stuff goes in /usr.– Paul RFeb 6, 2015 at 10:22
If you don't have Command Line Tools installed you can run:
xcode-select --install
A dialogue box opens for you to accept the license agreement and so on.
(This was missing from the above responses.)
create/update a symlink for /usr/include
to have the libs detected:
sudo ln -sf /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /usr/include
The above path can be found by searching for stdio.h
find /Applications/Xcode.app -path '*/usr/include/stdio.h'
I have to do this with every XCode/MacOS SDK update, Faced this today with the XCode 7 upgrade.
Once the command line tools are installed, they cannot be re-installed with xcode-select
, so the path may not be updated with a Mac AppStore upgrade.
Uninstalling & Reinstalling XCode and then running xcode-select --install
might update the path, but is an overkill.
Some posts also mention xcode-select --switch /Application/Xcode.app
, but I didn't have much luck with it.
-
3Apple no longer allows you to do this:
ln: /usr/include: Operation not permitted
. (And yes, I did try it withsudo
, and yes, I do have the password.) Aug 4, 2020 at 15:14
The root reason is missing the /usr/include folder, installing command-line tools sometimes will not automatically add it.
Install the package at
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
-
3I am on MacOS Mojave, but I am not able to find this
Packages
directory underCommandLineTools
.– jiashenCSep 4, 2019 at 14:15 -
Yes, I did install the comand line tool, but there is no such package. Anyway, asked my colleague to share the package with me.– jiashenCSep 11, 2019 at 12:05
-
1if /usr/include still not exist after install CommandLineTools, can create a link by run commad sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ /usr/include– jolestarOct 11, 2019 at 7:47
-
1@jolestar When I try to make that link. MacOS replies,
ln: /usr/include: Operation not permitted
. Yes, I triedsudo
, and yes, I know the password. Aug 4, 2020 at 15:15 -
In my laptop it appears in many locations like /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
.
If you already built your locate database, you can use
locate stdio.h
If you haven't already, build it. The locate
command is awesome!
Due to Apple's new System Integrity Protection (SIP), you will run into this error when attempting the solution of creating/updating a symlink to /usr/include
ln: /usr/include: Operation not permitted
Instead of disabling SIP, the better way to do it is to create symlinks in /usr/local/include
instead, e.g.
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
This works for people who have already installed CommandLineTools and was unable to find stdio.h
inside /usr/include
In the folder
Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
or similar.
I have installed "CommandLineTools", and the "stdio.h" file exist in both Xcode and CommandLineTools diretory.
/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
This is my path for C/C++ library in M1 Mac 2022
/Library/Developer/CommandLineTools/usr/include/c++/v1
<stdio.h>
header file is part of the C standard library, and may be in any directory that the compiler searches for header files, it may be in a sub-directory to/usr/lib
for example. Also, the commandfind ./ -iname "stdio.h"
search for the file from the current directory, so if you're in e.g. your own home-directory you will not find the file.