ios - xCode 项目未在 macOS Catalina 10.15.5 上找到 c++ 标准库

标签 ios c swift xcode metalkit

我有一个使用 Metal 的 xCode Swift 5 项目,它有两个目标,主应用程序和一个构建第三方 C 库的静态库目标。当我编译项目时,错误消息(见下文)表明 xCode 正在 iPhone SDK 中搜索系统 C 头文件,但它没有找到,也没有在任何地方找到它们。我怎样才能解决这个问题?请 :)

  • 静态库目标构建第三方 C 库,并具有 Obj-c 公共(public) h/m 文件(AGBGPUType.h、AGBGPUType.m)。
  • 在 Swift/Metal 项目的桥接头文件 (Common.h) 中引用了这个库头文件。
  • 所有内部库头文件和相关源代码都包含在 Swift/Metal 项目中——这不是一个工作区,它是一个具有两个目标的单个项目。
  • 构建应用程序目标的方案设置为首先编译库,然后是应用程序,我正在构建的设备是运行 iOS 13.5 的 iPhone Xs Max。

  • 我已经设置了 C 库的公共(public) Obj-c (.h & .m) 以登录到控制台并创建对字体库的引用——这意味着它可以以功能方式访问第三方 C 库代码。

    库 obj-c 文件是:
    #import "AGBGPUType.h"
    #import "ft2build.h"
    #include FT_FREETYPE_H
    #include FT_STROKER_H
    
    @implementation AGBGPUType
    
    FT_Library _fontLibrary;
    FT_Face _face;
    FT_GlyphSlot _glyph;
    FT_Stroker _stroker;
    
    -(void) simple {
      int giddy = 5000;
      NSLog(@"From main library objc AGBGPUType.m %d", giddy);
    
      if(FT_Init_FreeType(&_fontLibrary)) {
          NSLog(@"Could not init Freetype library");
      }
    
    }
    
    @end
    

    Swift/Metal 应用程序中的桥接头文件有:
    #ifndef Common_h
    #define Common_h
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #import <simd/simd.h>
    
    #import "AGBGPUType/AGBGPUType.h"
    ...
    #endif
    

    构建应用程序时会产生以下错误:
    CompileMetalFile /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal (in target 'IncuFlic' from project 'IncuFlic')
        cd /Users/username/Documents/xCode/IncuFlic
        export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal -c -target air64-apple-ios13.5 -gline-tables-only -MO -I/Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Build/Products/Debug-iphoneos/include -F/Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Build/Products/Debug-iphoneos -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk -ffast-math -serialize-diagnostics /Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Build/Intermediates.noindex/IncuFlic.build/Debug-iphoneos/IncuFlic.build/Metal/Shaders.dia -o /Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Build/Intermediates.noindex/IncuFlic.build/Debug-iphoneos/IncuFlic.build/Metal/Shaders.air -index-store-path /Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Index/DataStore "" -MMD -MT dependencies -MF /Users/username/Library/Developer/Xcode/DerivedData/IncuFlic-fxtjxtzaumyrcuhiwrtiajlsnzak/Build/Intermediates.noindex/IncuFlic.build/Debug-iphoneos/IncuFlic.build/Metal/Shaders.dat /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal
    
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal:35:
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Common.h:33:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/stdio.h:64:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_stdio.h:68:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
    ##error Unsupported architecture##
     ^
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal:35:
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Common.h:33:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/stdio.h:64:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_stdio.h:71:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_types.h:27:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:33:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
    ##error architecture not supported##
     ^
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal:35:
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Common.h:33:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/stdio.h:64:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_stdio.h:71:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_types.h:27:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'
    typedef __int64_t       __darwin_blkcnt_t;      /* total blocks */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'
    typedef __int32_t       __darwin_blksize_t;     /* preferred block size */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:57:9: error: unknown type name '__int32_t'
    typedef __int32_t       __darwin_dev_t;         /* dev_t */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:60:9: error: unknown type name '__uint32_t'
    typedef __uint32_t      __darwin_gid_t;         /* [???] process and group IDs */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:61:9: error: unknown type name '__uint32_t'
    typedef __uint32_t      __darwin_id_t;          /* [XSI] pid_t, uid_t, or gid_t*/
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:62:9: error: unknown type name '__uint64_t'; did you mean 'uint64_t'?
    typedef __uint64_t      __darwin_ino64_t;       /* [???] Used for 64 bit inodes */
            ^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/metal/ios/lib/clang/3902.67/include/metal/metal_types:48:25: note: 'uint64_t' declared here
    typedef __UINT64_TYPE__ uint64_t;
                            ^
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal:35:
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Common.h:33:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/stdio.h:64:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_stdio.h:71:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_types.h:27:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:68:9: error: unknown type name '__darwin_natural_t'
    typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:70:9: error: unknown type name '__uint16_t'
    typedef __uint16_t      __darwin_mode_t;        /* [???] Some file attributes */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:71:9: error: unknown type name '__int64_t'
    typedef __int64_t       __darwin_off_t;         /* [???] Used for file sizes */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:72:9: error: unknown type name '__int32_t'
    typedef __int32_t       __darwin_pid_t;         /* [???] process and group IDs */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:73:9: error: unknown type name '__uint32_t'
    typedef __uint32_t      __darwin_sigset_t;      /* [???] signal set */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:74:9: error: unknown type name '__int32_t'
    typedef __int32_t       __darwin_suseconds_t;   /* [???] microseconds */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:75:9: error: unknown type name '__uint32_t'
    typedef __uint32_t      __darwin_uid_t;         /* [???] user IDs */
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:76:9: error: unknown type name '__uint32_t'
    typedef __uint32_t      __darwin_useconds_t;    /* [???] microseconds */
            ^
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Shaders.metal:35:
    In file included from /Users/username/Documents/xCode/IncuFlic/IncuFlic/Common.h:33:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/stdio.h:64:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_stdio.h:71:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/_types.h:27:
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_types.h:80:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_pthread/_pthread_types.h:58:25: error: pointer type must have explicit address space qualifier
            void (*__routine)(void *);      // Routine to call
                                   ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_pthread/_pthread_types.h:59:7: error: pointer type must have explicit address space qualifier
            void *__arg;                    // Argument to pass
                 ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk/usr/include/sys/_pthread/_pthread_types.h:60:38: error: pointer type must have explicit address space qualifier
            struct __darwin_pthread_handler_rec *__next;
    

    其他环境详细信息

    我的路
    须藤纳米/etc/paths
    /usr/local/bin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    

    当前活跃的开发者目录
    xcode-选择-p
    /Applications/Xcode.app/Contents/Developer
    

    GCC 编译器 gcc -v
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 11.0.3 (clang-1103.0.32.62)
    Target: x86_64-apple-darwin19.5.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    

    C 预处理器 cpp -v
    Apple clang version 11.0.3 (clang-1103.0.32.62)
    Target: x86_64-apple-darwin19.5.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
     "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I /usr/include -I/usr/local/include -internal-isystem 
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem 
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include -internal-externc-isystem 
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem 
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdebug-compilation-dir /Users/annstramer -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -traditional-cpp -o - -x c -
    clang -cc1 version 11.0.3 (clang-1103.0.32.62) default target x86_64-apple-darwin19.5.0
    
    ignoring nonexistent directory "/usr/include"
    ignoring nonexistent directory "/usr/local/include"
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
    
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
    
    include "..." search starts here:
    include <...> search starts here:
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    
  • 通过阅读几篇文章,包括 Broken c++ std libraries on macOS High Sierra 10.13How can I find all Clang versions installed on my Mac? ,可能 xCode 没有找到 C 安装的 header 。错误消息表明 xCode 正在 iPhone13.5 sdk 中查找文件,但终端命令似乎确认该 sdk 中不包含 C 版本。
  • xCode 开发者目录中存在 C 安装。
  • 当库作为预建存档包含在 Obj-c 项目或 Swift 项目中时,项目编译时不会出错,找到 C 头文件,将消息记录到控制台并创建对字体库的引用。 Golden - 但在 Swift/ 中的桥接头根本不起作用金属 项目。该桥接头中有几个结构可以在 Swift/Metal 代码的其他领域完美运行。
  • xCode 的(蛮力)干净安装并没有解决问题,安装命令行工具也没有解决问题,这两个都是在安装最近的 Catalina 升级之后安装了相对最近的 Catalina 的干净安装,然后就在今天安装了命令行工具升级。

  • 我的问题:
  • 我对 xCode 没有找到 C 安装是否正确?
  • cpp -v 找到xCode的C安装,为什么xCode在编译时没有?
  • 请问,解决这个问题的正确专业方法是什么?

  • 提前感谢您的见解。

    最佳答案

    这是 Cecelia Humlelu 对这个问题的一个很好的解释。
    https://www.youtube.com/watch?v=NvURClY2Xzk
    我发现这个关于如何集成 C 库的解释也非常直接,并且与 xCode 11 是同时代的:https://www.youtube.com/watch?v=WQI02KR9kQw
    我通过在 ObjC 库目标中构建 C 库,然后使用 ObjC 访问库来将 C 库集成到 Swift 项目中。

  • 由于 Swift 可以直接使用 C,我删除了 Obj-C 库目标,从命令行构建了 C 库,并将存档和标题放入项目中(参见第二个视频链接)。 Cecelia 视频的前 6 分钟是理解这些更改为何奏效的关键,从 6:45 开始的 C/Swift 部分清楚地概述了我所遵循的内容。给信。
  • 在这个项目中,桥接头被导入到金属着色器中。我正在使用 Obj-C 头文件在桥接头中导入 C 库。删除这个 Obj-C header 并编写 C 函数一开始似乎是可行的。
  • 然而,当涉及到使用库的核心功能时,还有另一个问题。这个库涉及处理字符串,并且要将字符串从 Swift 函数调用传递到 C 函数调用,必须将指针参数添加到使用库代码的 C 函数调用中。在 GPU 上运行代码需要地址空间限定符。由于 C 函数是通过 Metal 在桥接头中导入的,因此编译器需要代码来指定地址空间标识符。问题是 C 没有用于指定指针参数地址空间的构造,因此无法在桥接头中导入这些函数声明。请注意:有一些 C 声明不需要地址空间限定符,讨论超出了这个问题的范围。
  • 在 xCode 项目中,每个目标只允许一个桥接头,但还有另一种导入头文件的方法。我为库头文件创建了一个模块映射,并将其添加到项目build设置中的 Swift Compiler Search Paths 的 Import Paths 设置中。因为这个库使用复杂的宏来公开功能,所以仍然需要一个 C 或 Obj-C 包装器来使用 Swift 中的库,但是这个库是完全集成的,并且可以从 CPU 代码中访问。
  • 在工作解决方案中,Swift 将模块映射中的头文件识别为全局定义的,因此可以从项目中的任何 Swift 文件中调用它们,目标的桥接头中不再引用库头文件。
  • 我按照视频中关于为 C 库创建模块映射的指南中的信函进行操作。

  • 这是 Obj-C 源文件声明:
    #import <LibraryWrapperCode.h>
    #import <MetalKit/MetalKit.h>
    #include "ft2build.h"
    #include FT_FREETYPE_H
    
    @implementation LibraryWrapperCode {
        FT_Library _fontLibrary;
        FT_Face _face;
        FT_GlyphSlot _glyph;
    }
    
    
    模块图:
    module GPUTextCWrapper {
      header "../GPUText/libraryWrapperCode.h"
      export *
    }
    
    C 库是从任何 Swift 文件中导入的:
    import GPUTextCWrapper
    
    我仍然不清楚我在做什么生成了这个问题中记录的错误消息,但我认为我导入库的方式是编译器发现它两次,第二次尝试重新编译库.如果我找到更直接的解释,我将再次更新此答案。

    关于ios - xCode 项目未在 macOS Catalina 10.15.5 上找到 c++ 标准库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62272159/

    相关文章:

    ios - 使用 CloudKit 进行 NSPredicate 不区分大小写的字符串搜索

    ios - Core Plot - 绘制较少点时的 X 轴移动位置

    ios - 不区分大小写的字符串搜索 - iphone

    c# - 将结构数组从 c 返回到 c#

    c - 如何强制openGL绘制非凸填充多边形

    ios - 尽管将内容添加到 plist 中,但在使用时请求授权不起作用

    ios - SwiftUI 无法添加 onChange 事件

    使用 Mongoose 创建双网络/套接字服务器

    ios - 堆栈 View 错误还是我错过了什么?

    ios - 将对象移动到屏幕中央