C语言 我在 Mac 中的“stdio.h”在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28362994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:43:54  来源:igfitidea点击:

Where is my "stdio.h" in Mac?

cmacos

提问by user3595632

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/includeor /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 testcommand 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.

我知道 Mac OS X 是一个基于 Unix 的系统。我听说 stdio.h 等 C 标准库位于/usr/local/include或 中/usr/include。但是这个目录下没有任何类型的库。我使用终端来搜索这个目录,我也使用类似的命令find ./ -iname "stdio.h",但没有任何结果。然而,奇怪的是,gcc -test.c -o test命令奏效了。它怎么发生的?我想知道我的 C 库在哪里。ps 我也使用 Xcode。与这个应用程序有关吗?帮我!我有 AWS EC2 linux 服务器,它有我上面提到的两个库。

回答by Paul R

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:

如果你有 Xcode 但没有安装可选的命令行工具包,那么标准的包含和库可能不会在通常的地方找到。尝试:

$ 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/includeand /usr/lib.

但是,如果您计划进行任何非 Xcode(即命令行)编程,则可能需要安装命令行工具包。然后,您将在/usr/include和 中看到常用的头文件和库/usr/lib

回答by polarise

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.)

(以上回复中缺少这一点。)

回答by Tarun

create/update a symlink for /usr/includeto have the libs detected:

创建/更新符号链接/usr/include以检测库:

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

上面的路径可以通过搜索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.

我必须在每次 XCode/MacOS SDK 更新时都这样做,今天面对 XCode 7 升级。

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.

一旦安装了命令行工具,它们就无法通过 重新安装xcode-select,因此路径可能无法通过 Mac AppStore 升级来更新。

Uninstalling & Reinstalling XCode and then running xcode-select --installmight update the path, but is an overkill.

卸载 & 重新安装 XCode 然后运行xcode-select --install可能会更新路径,但这是一种矫枉过正。

Some posts also mention xcode-select --switch /Application/Xcode.app, but I didn't have much luck with it.

一些帖子也提到了xcode-select --switch /Application/Xcode.app,但我没有太多运气。

回答by jolestar

The root reason is missing the /usr/include folder, installing command-line tools sometimes will not automatically add it.

根本原因是缺少 /usr/include 文件夹,安装命令行工具有时不会自动添加它。

Install the package at

安装包在

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

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

回答by Alexander Perechnev

In my laptop it appears in many locations like /usr/include/stdio.hand /usr/include/sys/stdio.hand /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h.

在我的笔记本电脑看起来像许多地方/usr/include/stdio.h/usr/include/sys/stdio.h/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h

回答by Maxim Chetrusca

If you already built your locate database, you can use

如果您已经构建了定位数据库,则可以使用

locate stdio.h

If you haven't already, build it. The locatecommand is awesome!

如果您还没有,请构建它。该locate命令是真棒

回答by yikibug

I have installed "CommandLineTools", and the "stdio.h" file exist in both Xcode and CommandLineTools diretory.

我已经安装了“CommandLineTools”,并且“stdio.h”文件存在于 Xcode 和 CommandLineTools 目录中。

/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

/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

回答by emlai

In the folder

在文件夹中

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

or similar.

或类似。