【问题标题】:'stdio.h' File Not Found When Compiling Hello World编译 Hello World 时未找到“stdio.h”文件
【发布时间】:2019-01-17 05:38:10
【问题描述】:

编辑:在本文末尾添加了$cc -v main.c 的输出。

我正在使用旧的 Xcode,因为我的内核扩展将支持 El Capitan。通过从较旧的 Xcode 构建复制 10.11 SDK,这适用于 8.3。

#include <stdio.h>   // 'stdio.h' file not found

int main( int argc, char **argv )
{
   printf( "Hello World!\n" );

   return 0;
}

$ ls -l /usr/include/stdio.h
-r--r--r--  1 root  wheel  19154 Feb  4  2017 /usr/include/stdio.h

$ ls -l /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h
-r--r--r--  7 mike  staff  19154 Feb  3  2017 /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h

我正在尝试构建一个用户空间命令行工具来测试我的内核扩展。

这是一个比较常见的问题,但到目前为止我尝试过的解决方案都没有奏效。在 Visual Studio 中发生了很多关于它的报告,而不仅仅是 Xcode。

刚才我重新安装了命令行工具。我将 SDK 从“最新的 macOS”更改为“macOS 10.12”。

源文件名为“main.c”——也就是说,不是“main.cpp”。

$ cc -v main.c
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 278.4 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0 -fdebug-compilation-dir /Users/mike/Projects/RCI/trunk/HD1/ButtonTest -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -x c main.c
clang -cc1 version 8.1.0 (clang-802.0.42) default target x86_64-apple-darwin16.7.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.

"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library

/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out
/var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -lSystem

/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/lib/darwin/libclang_rt.osx.a

【问题讨论】:

  • 尝试打印 GCC 包含路径?
  • 这一定是某种安装问题。我们需要更多的诊断信息。请运行命令cc -v main.c,然后将该命令的完整且未编辑的输出编辑到您的问题中。
  • 检查您的安装 — 有问题。也许运行xcode-select 会有所帮助:xcode-select -h 提供帮助,xcode-select -p 提供路径信息,xcode-select --install 安装/配置 XCode。鉴于您在磁盘上有/usr/include/stdio.h,您得到“未找到”有点令人惊讶,但这意味着编译器必须在其他地方寻找。
  • zwol - 如果我从命令行运行,“gcc main.c”会构建“a.out”。只是在 IDE 中找不到
  • 这个问题可能是因为 Xcode 在一个文件夹中,所以我可以安装多个版本。但我多年来一直这样做,没有遇到这样的麻烦。 "/Applications/Xcode_8.3/Xcode.app"

标签: c xcode macos compiler-errors include


【解决方案1】:

我不应该喝酒和编码:

我的项目起初只有一个目标,即内核扩展。后来我为命令行工具添加了第二个目标。

当我为我的命令行工具创建一个新的源文件时,该源不知何故被添加到内核扩展的目标中。更改工具的标题搜索路径设置对我的问题没有影响,因为源不在工具的目标中。

内核扩展 - 设备驱动程序 - 具有仅来自 Kernel.framework 的标头,其中没有 stdio.h 文件。

我现在就闭嘴。

【讨论】:

    猜你喜欢
    • 2012-01-20
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2020-09-11
    • 2011-07-12
    • 2013-05-11
    • 2015-02-21
    • 1970-01-01
    相关资源
    最近更新 更多