xcode MacOS Mojave 中的 C 头文件在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53169970/
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-15 10:51:44  来源:igfitidea点击:

Where are the C headers in MacOS Mojave?

cxcodemacosheader-filesmacos-mojave

提问by Matthieu Brucher

It seems that Apple keeps on moving their tools around and the old solution of installing the command line tools are with using xcode-select --installdoesn't work.

Apple 似乎一直在移动他们的工具,并且安装命令行工具的旧解决方案与 usingxcode-select --install不起作用。

In Mojave, xcode-selectdoesn't install anything anymore (the GUI always fails to find the package) and the command line tools don't install itself in /usr/or /usr/local.

在 Mojave 中,xcode-select不再安装任何东西(GUI 总是无法找到包)并且命令行工具不会将自身安装在/usr//usr/local.

采纳答案by olehermanse

xcode-select --installdid work for me in Mojave. Maybe you can try installing XCode from Mac App Store, and then install developer tools?

xcode-select --install在莫哈韦沙漠对我来说有效。也许您可以尝试从 Mac App Store 安装 XCode,然后安装开发人员工具?

Regarding header locations, I have Apples headers in /Library/Developer/CommandLineTools/:

关于标题位置,我有苹果标题/Library/Developer/CommandLineTools/

$ sudo find /Library -name stdio.h 
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h

And if you install gcc via brew, it will add headers in /usr/local/:

如果您通过 brew 安装 gcc,它将在/usr/local/以下位置添加标题:

$ sudo find /usr -name stdio.h 
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include-fixed/stdio.h
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/include-fixed/stdio.h
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/tr1/stdio.h
/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/gcc/x86_64-apple-darwin17.3.0/7.3.0/include/ssp/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/include/c++/7.3.0/tr1/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/lib/gcc/7/gcc/x86_64-apple-darwin17.5.0/7.3.0/include/ssp/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/lib/gcc/7/gcc/x86_64-apple-darwin17.5.0/7.3.0/include-fixed/stdio.h
/usr/local/include/c++/8.2.0/tr1/stdio.h
/usr/local/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include/ssp/stdio.h
/usr/local/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include-fixed/stdio.h

(Those are not Apple's headers, but GCC / GLIBC).

(那些不是 Apple 的标题,而是 GCC / GLIBC)。

Using dtruss I can see that Apple clang uses the one in CommandLineTools/SDKs:

使用 dtruss 我可以看到 Apple clang 使用了一个CommandLineTools/SDKs

$ sudo dtruss -f sudo -u $USER clang test.c -o test 2>&1
3781/0x51d8:  pread(0x3, "#include <stdio.h>\n\nint main(void)\n{\n  printf(\"Hello, world\n\");\n  return 0;\n}\n##代码##", 0x4F, 0x0)              = 79 0
3781/0x51d8:  __pthread_sigmask(0x3, 0x7FFEE3A7E768, 0x7FFEE3A7E76C)            = 0 0
3781/0x51d8:  close(0x3)                = 0 0
3781/0x51d8:  __pthread_sigmask(0x3, 0x7FFEE3A7E76C, 0x0)               = 0 0
3781/0x51d8:  open("/usr/local/include/stdio.h##代码##", 0x1000000, 0x1A)             = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include/stdio.h##代码##", 0x1000000, 0x48)               = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/usr/include/stdio.h##代码##", 0x1000000, 0x37)                = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h##代码##", 0x1000000, 0x47)                = 3 0

回答by mpmeyer

Per the following article: https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/

根据以下文章:https: //silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave /

This will install the headers:

这将安装标头:

open /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 Eric Postpischil

Xcode now supports multiple SDKs and multiple installations of Xcode. The SDKs are inside Xcode.app, and Xcode.app is installed by default in Applications but may be elsewhere.

Xcode 现在支持多个 SDK 和多个 Xcode 安装。SDK 在 Xcode.app 中,Xcode.app 默认安装在 Applications 中,但也可能在其他地方。

xcrun --show-sdk-pathwill show a default SDK path, but there may be others. For example, one possible path is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk. From there, usr/includeholds common public headers such as the standard C headers, and various Apple headers are in frameworks under System.

xcrun --show-sdk-path将显示默认的 SDK 路径,但可能还有其他路径。例如,一种可能的路径是/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk。从那里开始,usr/include保存了常见的公共头文件,例如标准的 C 头文件,并且各种 Apple 头文件都在System.

In /Applications/Xcode.app/Contents/Developer/Platforms, you will likely find folders for other platforms, such as iPhoneOS.platformand AppleTVOS.platform. Within those, Developer/SDKsleads to SDKs for those platforms.

在 中/Applications/Xcode.app/Contents/Developer/Platforms,您可能会找到其他平台的文件夹,例如iPhoneOS.platformAppleTVOS.platform。在这些中,Developer/SDKs导致了这些平台的 SDK。