代码之家  ›  专栏  ›  技术社区  ›  Mike Crawford

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

  •  0
  • Mike Crawford  · 技术社区  · 7 年前

    编辑:添加的输出 $cc -v main.c 在这篇文章的结尾。

    我使用一个旧的Xcode,因为我的内核扩展将支持El-Capitan。通过从旧的Xcode构建中复制10.11sdk,它可以与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”-也就是说, “主.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
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Mike Crawford    7 年前

    我不应该喝酒和编码:

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

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

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

    我现在闭嘴。