【问题标题】:GCC cannot find stdio.h with OS X even though command line tools is installed即使安装了命令行工具,GCC 也无法在 OS X 中找到 stdio.h
【发布时间】:2015-07-30 02:48:15
【问题描述】:

我使用的是 OS X 10.10.4,但无法编译 .c 文件。我在这个问题上找到的大多数帮助建议安装 Xcode 的命令行工具,但是尝试这样做会给出

xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

我使用 find 选项来定位 stdio.h

find /Applications/Xcode.app -name stdio.h
/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

很明显,它有几个位置。

我尝试在编译时添加“-v”标志以尝试获得更多洞察力,但发现它搜索的不是很彻底。

#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

有人可以帮忙吗?

【问题讨论】:

  • 俄罗斯猫头鹰,如果你通过缩进四个空格而不是反引号来编写代码,它可以解决你的八字问题 - 我已经调整了你的文本来做到这一点。要为大块快速完成,只需标记所有文本并使用 CTRL-K。如果我能帮助你解决实际问题就好了:-)
  • 无论如何都是有用的提示。谢谢!

标签: c xcode gcc compilation osx-yosemite


【解决方案1】:
  • 首先,OSX 上的默认编译器是 clang 而不是 gcc 所以最好使用clang
  • 如果你必须使用gcc你可以通过编译选项-I option设置头搜索路径(示例: gcc -Ipath_to_headers yourprogram.c -o yourprogram

【讨论】:

  • 非常感谢!那行得通。老实说,我一直以为我一直在使用 gcc,但 clang 立即起作用了。
猜你喜欢
  • 2021-09-21
  • 2019-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-25
  • 2020-08-29
相关资源
最近更新 更多