Strange linker error mentioning `_swift_getTypeByMangledNameInContextInMetadataState`

As I've reported in this issue when using $(inherited) in LIBRARY_SEARCH_PATHS I'm getting the following linker error:

Undefined symbols for architecture x86_64:
  "_swift_getTypeByMangledNameInContextInMetadataState", referenced from:
      ___swift_instantiateConcreteTypeFromMangledNameAbstract in Backend.o
      ___swift_instantiateConcreteTypeFromMangledNameAbstract in DP3TSDK.o
ld: symbol(s) not found for architecture x86_64

The only other places where I've seen this issue mentioned have been in relation to React Native projects. The issue above is also in a React Native project.

The workaround is to remove the $(inherited) entry and setting all the LIBRARY_SEARCH_PATHS manually. However, I fail to understand how that makes a difference.

The only thing that is "removed" from LIBRARY_SEARCH_PATHS by doing this is two entries to the swift toolchain:

  • toolchain/usr/lib/swift/iphoneos
  • toolchain/usr/lib/swift-5.0/iphoneos

So I'm at a loss to understand what's going on.

The symbol in question is part of the swift runtime.

It sounds like you're trying to link against an older Swift runtime while targeting a newer OS. swift_getTypeByMangledNameInContextInMetadataState was added in iOS 13.4 IIRC, and is not in older OS runtimes, nor is it in the Swift 5.0 runtime used for backward deployment to pre-Swift-ABI OSes. You shouldn't need to add the toolchain library paths to LIBRARY_SEARCH_PATHS yourself, because Xcode will automatically include those libraries if your minimum deployment target is old enough to need them.

1 Like

It sounds like you're trying to link against an older Swift runtime while targeting a newer OS.

It turns out that at the Project level, not the Target level, someone had defined:

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

:man_facepalming:

After removing that, and making sure everything is targeting iOS 13.5, the error has gone away. Thanks for your help Joe :+1:

Terms of Service

Privacy Policy

Cookie Policy