c - 编译 Hello World 时未找到“stdio.h”文件

标签 c xcode macos compiler-errors include

编辑:在本文末尾添加了 $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

最佳答案

我不应该喝酒和编码:

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

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

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

我现在就闭嘴。

关于c - 编译 Hello World 时未找到“stdio.h”文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51772369/

相关文章:

ios - 当CollectionView只有一个项目时,如何使垂直uiCollectionViewCell变为左侧

xcode - Cocoa:如何在表中添加自定义行?或者其他方式?

c - C 中包含指针的段错误(核心转储)

c - 如何从文本文件中读取特殊字符?

C线程调度(和asm)

ios - 使大型 UIView 适合内容 View

ios - 用于 Retina iPad 图像的正确后缀是什么?

ios - 为 iOS 编译 yaml.swift 时遇到问题(为 OSX 构建良好)

objective-c - 如何将 NSPredicateEditor/NSRuleEditor 背景设置为交替行?

c++ - 如何修复堆错误?