"Could not find or use auto-linked library" during linking

Hey! I would greatly appreciate your help with the following problem:

I'm trying to link multiple .o files to create an executable using the Swift toolchain (not using Xcode or SwiftPM). Previously (using the swift-5.2.4-RELEASE toolchain), the following command did the job and emitted an executable:

/path/to/toolchain/usr/bin/swift --driver-mode=swiftc -emit-executable main.o library.o anotherLibrary.o

But when I use the swift-5.3-RELEASE toolchain, I get these errors:

ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftsimd'
ld: warning: Could not find or use auto-linked library 'swiftGLKit'
ld: warning: Could not find or use auto-linked library 'swiftSceneKit'
ld: warning: Could not find or use auto-linked library 'swiftModelIO'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftAppKit'
ld: warning: Could not find or use auto-linked library 'swiftIOKit'
ld: warning: Could not find or use auto-linked library 'swiftXPC'
ld: warning: Could not find or use auto-linked library 'swiftCoreData'

When I compared the package content of the two versions of the toolchain, I noticed that the 5.2.4 toolchain included all of the libraries that I need in the usr/lib/swift/macosx directory, while the 5.3 toolchain doesn't seem to include these.
I'm not sure if this is the cause of the problem, but if it is, I suppose I need to give the compiler a search path for these libraries on my machine? What would that look like? Or am I missing something else?

Again, any ideas or help would be greatly appreciated!

Found the issue!
I needed to set the path to the macOS SDK. The command now looks like this:

/path/to/toolchain/usr/bin/swift --driver-mode=swiftc -emit-executable main.o library.o anotherLibrary.o -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk

I get the same issue but my repro is totally different, and I'm building with Xcode. As soon as I set my project to a Deployment Target of 14.0, the error appears, and then when I revert that change, it disappears. Couldn't find anything in the Xcode 12 release notes that referenced this.

ld: warning: Could not find or use auto-linked library 'swiftAVFoundation'
Undefined symbols for architecture x86_64:
  "_swiftoverride_class_getSuperclass(swift::TargetMetadata<swift::InProcess> const*)", referenced from:
      swift::swift50override_conformsToProtocol(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const* (*)(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*)) in libswiftCompatibility50.a(ProtocolConformance.cpp.o)
  "swift::swift51override_conformsToSwiftProtocol(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef, swift::TargetProtocolConformanceDescriptor<swift::InProcess> const* (*)(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef))", referenced from:
      _Swift50Overrides in libswiftCompatibility50.a(Overrides.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Happy to share project with anyone at Apple if they want to debug.

Could you file a bug report through feedbackassistant.apple.com? That should allow you to attach your project and provide reproduction steps.

Did anyone find clear fixes to these? I'm hitting this same case in a project where there is definitely some messing with auto-linking, but I'm not sure what library to provide to satisfy this error when deploying for iOS 11

In my case passing -lswiftCompatibility51 to the link resolves the issue. So I guess something is wrong earlier in the chain (likely in the tooling that produced this binary) that causes that not to be present in the .o files LC_LINKER_OPTION's

Terms of Service

Privacy Policy

Cookie Policy