Swift链接器错误:确定可用的API演示文稿的未定义符号

我正在开发一个使用presentationDimensions(...) API的相机应用程序:

if #available(iOS 13.0, *) {
  let leftVideo = self.formatDescription.presentationDimensions()
  let rightVideo = other.formatDescription.presentationDimensions()
  // ...
}

现在,当我尝试构建项目时,出现以下错误:

未定义符号:(CoreMedia 中的扩展):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize

这是最后的 Xcode 日志(错误):

Ld /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/VisionCameraExample.app/VisionCameraExample normal (in target 'VisionCameraExample' from project 'VisionCameraExample')
    cd /Users/mrousavy/Projects/react-native-vision-camera/example/ios
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios12.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/CocoaAsyncSocket -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/DoubleConversion -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/FBReactNativeSpec -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-DoubleConversion -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-Folly -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-Glog -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-PeerTalk -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Flipper-RSocket -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/FlipperKit -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Folly -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/RCTTypeSafety -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-Core -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-CoreModules -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTAnimation -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTBlob -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTImage -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTLinking -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTNetwork -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTSettings -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTText -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-RCTVibration -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-cxxreact -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsi -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsiexecutor -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/React-jsinspector -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/ReactCommon -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/Yoga -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/YogaKit -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/glog -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/libevent -L/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/react-native-vision-camera -F/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos -F/Users/mrousavy/Projects/react-native-vision-camera/example/ios/Pods/OpenSSL-Universal/Frameworks -F/Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/XCFrameworkIntermediates/OpenSSL -filelist /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample.swiftmodule -ObjC -lCocoaAsyncSocket -lDoubleConversion -lFBReactNativeSpec -lFlipper -lFlipper-DoubleConversion -lFlipper-Folly -lFlipper-Glog -lFlipper-PeerTalk -lFlipper-RSocket -lFlipperKit -lFolly -lRCTTypeSafety -lReact-Core -lReact-CoreModules -lReact-RCTAnimation -lReact-RCTBlob -lReact-RCTImage -lReact-RCTLinking -lReact-RCTNetwork -lReact-RCTSettings -lReact-RCTText -lReact-RCTVibration -lReact-cxxreact -lReact-jsi -lReact-jsiexecutor -lReact-jsinspector -lReactCommon -lYoga -lYogaKit -lglog -llibevent -lreact-native-vision-camera -lstdc++ -framework AudioToolbox -framework CFNetwork -framework JavaScriptCore -framework MobileCoreServices -framework OpenSSL -framework Security -framework UIKit -ObjC -lc++ -lPods-VisionCameraExample -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Intermediates.noindex/VisionCameraExample.build/Debug-iphoneos/VisionCameraExample.build/Objects-normal/arm64/VisionCameraExample_dependency_info.dat -o /Users/mrousavy/Library/Developer/Xcode/DerivedData/VisionCameraExample-aeiaddcztqvxgygupinrzjkkdodr/Build/Products/Debug-iphoneos/VisionCameraExample.app/VisionCameraExample

Undefined symbols for architecture arm64:
  "(extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize", referenced from:
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.isBetterThan(__C.AVCaptureDeviceFormat) -> Swift.Bool in libreact-native-vision-camera.a(AVCaptureDevice.Format+isBetterThan.o)
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.matchesFilter(__C.NSDictionary) -> Swift.Bool in libreact-native-vision-camera.a(AVCaptureDevice.Format+matchesFilter.o)
      (extension in react_native_vision_camera):__C.AVCaptureDeviceFormat.toDictionary() -> [Swift.String : Any] in libreact-native-vision-camera.a(AVCaptureDevice.Format+toDictionary.o)
     (maybe you meant: default argument 1 of (extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize, default argument 0 of (extension in CoreMedia):__C.CMFormatDescriptionRef.presentationDimensions(usePixelAspectRatio: Swift.Bool, useCleanAperture: Swift.Bool) -> __C.CGSize )
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我的 .pbxproj(剥离了不相关的部分,例如发布配置等):

// ...

/* Begin XCBuildConfiguration section */
        13B07F941A680F5B00A75B9A /* Debug */ = {
            isa = XCBuildConfiguration;
            baseConfigurationReference = 47F7ED3B7971BE374F7B8635 /* Pods-VisionCameraExample.debug.xcconfig */;
            buildSettings = {
                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
                CLANG_ENABLE_MODULES = YES;
                CURRENT_PROJECT_VERSION = 1;
                DEVELOPMENT_TEAM = CJW62Q77E7;
                ENABLE_BITCODE = NO;
                INFOPLIST_FILE = VisionCameraExample/Info.plist;
                LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
                OTHER_LDFLAGS = (
                    "$(inherited)",
                    "-ObjC",
                    "-lc++",
                );
                PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativevisioncamera;
                PRODUCT_NAME = VisionCameraExample;
                SWIFT_OBJC_BRIDGING_HEADER = "VisionCameraExample-Bridging-Header.h";
                SWIFT_OPTIMIZATION_LEVEL = "-Onone";
                SWIFT_VERSION = 5.0;
                VERSIONING_SYSTEM = "apple-generic";
            };
            name = Debug;
        };

// ...

        83CBBA201A601CBA00E9B192 /* Debug */ = {
            isa = XCBuildConfiguration;
            buildSettings = {
                ALWAYS_SEARCH_USER_PATHS = NO;
                CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
                CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
                CLANG_CXX_LIBRARY = "libc++";
                CLANG_ENABLE_MODULES = YES;
                CLANG_ENABLE_OBJC_ARC = YES;
                CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
                CLANG_WARN_BOOL_CONVERSION = YES;
                CLANG_WARN_COMMA = YES;
                CLANG_WARN_CONSTANT_CONVERSION = YES;
                CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
                CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
                CLANG_WARN_EMPTY_BODY = YES;
                CLANG_WARN_ENUM_CONVERSION = YES;
                CLANG_WARN_INFINITE_RECURSION = YES;
                CLANG_WARN_INT_CONVERSION = YES;
                CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
                CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
                CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
                CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
                CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
                CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
                CLANG_WARN_STRICT_PROTOTYPES = YES;
                CLANG_WARN_SUSPICIOUS_MOVE = YES;
                CLANG_WARN_UNREACHABLE_CODE = YES;
                CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
                "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
                COPY_PHASE_STRIP = NO;
                ENABLE_STRICT_OBJC_MSGSEND = YES;
                ENABLE_TESTABILITY = YES;
                GCC_C_LANGUAGE_STANDARD = gnu99;
                GCC_DYNAMIC_NO_PIC = NO;
                GCC_NO_COMMON_BLOCKS = YES;
                GCC_OPTIMIZATION_LEVEL = 0;
                GCC_PREPROCESSOR_DEFINITIONS = (
                    "DEBUG=1",
                    "$(inherited)",
                );
                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
                GCC_WARN_UNDECLARED_SELECTOR = YES;
                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                GCC_WARN_UNUSED_FUNCTION = YES;
                GCC_WARN_UNUSED_VARIABLE = YES;
                IPHONEOS_DEPLOYMENT_TARGET = 12.0;
                LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
                LIBRARY_SEARCH_PATHS = (
                    ""$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"",
                    ""$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"",
                    ""$(inherited)"",
                );
                MTL_ENABLE_DEBUG_INFO = YES;
                ONLY_ACTIVE_ARCH = YES;
                SDKROOT = iphoneos;
            };
            name = Debug;
        };

// ...

请注意,当我删除对presentationDimensions 的那些调用时,一切正常。

有人可以帮我从这里出去吗?该 API 从 iOS 13.0 开始可用,即使我的 iOS 部署目标是 11.0,我仍然应该能够构建它,不是吗?

回答

终于找到了答案。我已经SWIFT_VERSION固定到 5.0,但 iOS 13 附带了 Swift 5.2,所以将 Swift 固定到 5.2(并删除LIBRARY_SEARCH_PATH指向 5.0)解决了它。

这意味着,这:

                LIBRARY_SEARCH_PATHS = (
                    ""$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"",
                    ""$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"",
                    ""$(inherited)"",
                );
                SWIFT_VERSION = 5.0;

应该是这样的:

                LIBRARY_SEARCH_PATHS = (
                    ""$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"",
                    ""$(inherited)"",
                );
                SWIFT_VERSION = 5.2;

耶稣基督。


以上是Swift链接器错误:确定可用的API演示文稿的未定义符号的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>