Mac中的"stdio.h"在哪里?

use*_*632 18 c macos

我知道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服务器,它有两个我在上面参考过的库.

Pau*_*l R 28

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

$ find /Applications/Xcode.app -name stdio.h
Run Code Online (Sandbox Code Playgroud)

你可能会看到类似的东西:

/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
Run Code Online (Sandbox Code Playgroud)

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


pol*_*ise 24

如果您没有安装命令行工具,则可以运行:

xcode-select --install
Run Code Online (Sandbox Code Playgroud)

将打开一个对话框,供您接受许可协议等.

(上述回复中缺少这一点.)


小智 8

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

sudo ln -sf /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /usr/include
Run Code Online (Sandbox Code Playgroud)

通过搜索stdio.h可以找到上述路径

find /Applications/Xcode.app -path '*/usr/include/stdio.h'
Run Code Online (Sandbox Code Playgroud)

我必须对每个XCode/MacOS SDK更新执行此操作,今天通过XCode 7升级面对此问题.

安装命令行工具后,无法重新安装它们xcode-select,因此可能无法使用Mac AppStore升级更新路径.

卸载并重新安装XCode然后运行xcode-select --install可能会更新路径,但是过度杀伤.

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

  • Apple 不再允许您执行此操作:`ln: /usr/include: 不允许操作`。(是的,我确实用“sudo”尝试过,是的,我确实有密码。) (3认同)

jol*_*tar 5

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

将套件安装在

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

  • 我使用的是 MacOS Mojave,但我无法在“CommandLineTools”下找到这个“Packages”目录。 (2认同)