Table of contents

React Native 0.62 iOS Error: Undefined symbol: associated type descriptor for FloatLiteralType

React Native May 01, 2020 Viewed 10.3K Comments 0

Question

When upgrading React Native 0.61.5 to 0.62.2, the following error occurred during Xcode compilation.

ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
Undefined symbols for architecture x86_64:
  "associated type descriptor for FloatLiteralType", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated type descriptor for IntegerLiteralType", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "value witness table for Builtin.Int32", referenced from:
      full type metadata for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol witness table for Swift.Float : Swift._ExpressibleByBuiltinFloatLiteral in Swift", referenced from:
      associated type witness table accessor for FloatLiteralType : Swift._ExpressibleByBuiltinFloatLiteral in __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol witness table for Swift.Int : Swift._ExpressibleByBuiltinIntegerLiteral in Swift", referenced from:
      associated type witness table accessor for IntegerLiteralType : Swift._ExpressibleByBuiltinIntegerLiteral in __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol descriptor for Swift.ExpressibleByFloatLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByFloatLiteral.init(floatLiteral: A.FloatLiteralType) -> A", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated conformance descriptor for Swift.ExpressibleByFloatLiteral.FloatLiteralType: Swift._ExpressibleByBuiltinFloatLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol descriptor for Swift.ExpressibleByIntegerLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByIntegerLiteral.init(integerLiteral: A.IntegerLiteralType) -> A", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated conformance descriptor for Swift.ExpressibleByIntegerLiteral.IntegerLiteralType: Swift._ExpressibleByBuiltinIntegerLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftCompatibility50", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibility50_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility50_$_YogaKit)
  "__swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_YogaKit)
  "_swift_getForeignTypeMetadata", referenced from:
      type metadata accessor for __C.YGValue in libYogaKit.a(YGLayoutExtensions.o)
      type metadata accessor for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution

There are two ways to solve this issue.

1. Refer to the official upgrade code

Refer to the official upgrade helper webtool, https://react-native-community.github.io/upgrade-helper/?from=0.61.5&to=0.62.2, and modify your project code. The main changes are ios/RnDiffApp.xcodeproj/project.pbxproj and ios/Podfile .

2. Follow these steps to setup Xcode

We should submit local files first, or back up.

2.1 Add Swift

Create a new swift file under the project.

Create a new swift file under the project.

Select Swift File, fill in any file name, in the Would you like to configure an Objective-C bridging header? Pop-up box, select Don't Create .

In the Would you like to configure an Objective-C bridging header? Pop-up box, select Don't Create

Delete the swift file that has been created.

Delete the swift file that has been created.

Press Move to Trash .

选择 Move to Trash

2.2 Add LIBRARY_SEARCH_PATHS

In Xcode, Select Procjet -> Build Settings -> Library Search Paths. Add these items as follow.

"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"

"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"

"$(inherited)" 

Add LIBRARY_SEARCH_PATHS

2.3 Setting Dead Code Stripping to YES

In Xcode, select PROJECT -> Build Settings -> LInking -> Dead Code Stringpping, and change to YES.

Setting Dead Code Stripping to YES

2.4 Add LD_RUNPATH_SEARCH_PATHS

In Xcode, select Procjet -> Build Settings -> Runpath Search Paths, add /usr/lib/swift $(inherited) .

Add LD_RUNPATH_SEARCH_PATHS

Finally, Clean Build Folder and rebuild.

Updated May 02, 2020