xCode项目未在macOS Catalina 10.15.5上定位c ++ std库

问题描述 投票:2回答:1

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

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

我已经设置了C库的公共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;

其他环境详细信息

我的路径sudo nano / etc / paths

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

当前活动的开发者目录xcode-select -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安装的头文件。错误消息表明xCode正在iPhone13.5 sdk中查找文件,但是终端命令似乎确认该sdk中不包含C版本。
  • xCode开发人员目录中存在C安装。
  • 当库作为Obj-c项目或Swift项目的预建归档文件包含时,项目编译无误,找到C头,将消息记录到控制台并创建对字体库的引用。金色-但是在Swift / Metal项目中桥接头文件根本不起作用。该桥接头中有几种结构可完美地在Swift / Metal代码的其他区域中正常工作。
  • 一次(强力)全新安装xCode并没有解决问题,也没有安装命令行工具,这两者都是在安装了最近的Catalina升级版之后,相对于相对较干净的Catalina升级版之后,直到今天才安装的。命令行工具升级。

我的问题:

  1. 我是否纠正xCode找不到C安装位置?
  2. cpp -v找到xCode的C安装,为什么xCode在编译期间没有?
  3. 请问,解决此问题的正确专业方法是什么?

感谢您的见解。

ios c swift xcode metalkit
1个回答
0
投票

这里是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 header文件在桥接头中导入C库。 这是一个错误
  • [在工作解决方案中,Metal着色器仍会导入项目的桥接头文件,但是在桥接头文件中,我声明了一个C函数调用,然后在集成了C的C文件中实现,而不是导入Obj-C库头文件库功能。这是关键,请参见下面的代码摘录。 Swift将桥接头中的C函数声明识别为全局定义的,因此可以从项目中的任何Swift文件中调用它们,并且它们与其他所有swift文件一起位于项目目录中的C文件中实现-另见下文。基本上,桥接头用作C文件的头文件。 C库和Swift代码之间不再有任何Obj-C。
  • 我在视频的后面跟随了为C库创建模块映射的指导。

这里是桥接头:

#ifndef Common_h
#define Common_h

#import <simd/simd.h>

void simple(void);

#endif /* Common_h */

这里是实现该功能的.c文件

// This is the C library's header file
#import "GPUText/ft2build.h"
#include FT_FREETYPE_H

FT_Library _fontLibrary;

void simple () {
    int giddy = 5000;
    printf("Ann is a champion %d", giddy);

    if(FT_Init_FreeType(&_fontLibrary)) {
        printf("Could not init Freetype library");
    } else {
        printf("Victory, however small, long sought");
    }
}

模块图:

module GPUTextCWrapper {
  header "../GPUText/ft2build.h"
  export *
}

C库已导入到主视图控制器中:

import GPUTextCWrapper

并且在视图控制器的viewDidLoad中(或在项目中的任何swift文件中)对访问C库的函数的调用都是…:

simple()

这是项目目录的部分快照:partial snapshot of project directory

© www.soinside.com 2019 - 2024. All rights reserved.