Swift Windows "unable to load standard library for target 'x86_64-unknown-windows-msvc'"

Hi there.
I'm trying to install Swift on my Windows 10 machine.

I've installed Swift 6.0 from the package installer, as described here: Swift.org - Traditional Installation.

I've installed Visual Studio 2022 -- I installed the 2019 build tools using the Visual Studio Installer.

When trying to build a minimal executable SwiftPM package I get the following error:

D:\Code\hello>swift build
error: 'hello': Invalid manifest (compiled with: ["C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\JOEBLOG~1\\AppData\\Local\\Temp\\TemporaryDirectory.WEPqVZ\\vfs.yaml", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\", "-libc", "MD", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "6", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "6.0.0", "D:\\Code\\hello\\Package.swift", "-o", "C:\\Users\\JOEBLOG~1\\AppData\\Local\\Temp\\TemporaryDirectory.4P3XOM\\hello-manifest.exe"])
<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc'
error: 'hello': Invalid manifest (compiled with: ["C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\JOEBLOG~1\\AppData\\Local\\Temp\\TemporaryDirectory.OlEqiF\\vfs.yaml", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\", "-libc", "MD", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows", "-L", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "6", "-I", "C:\\Users\\Joe Bloggs\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "6.0.0", "D:\\Code\\hello\\Package.swift", "-o", "C:\\Users\\JOEBLOG~1\\AppData\\Local\\Temp\\TemporaryDirectory.C7kHTN\\hello-manifest.exe"])
<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc'

Trying to invoke the compiler on its own doesn't fair any better:

D:\Code\hello>swiftc -emit-executable -o a.exe Sources\main.swift
e[1m<unknown>:0: e[0me[0;1;31merror: e[0me[1munable to load standard library for target 'x86_64-unknown-windows-msvc'
e[0m

This is from a developer prompt. The results are the same from regular CMD and Powershell prompts.

I've enabled symlinks for standard users, and installed Python 3.9. Passing the flag -sdk %SDKROOT% doesn't improve the situation.

Any help would be appreciated.

Is the SDKROOT environment set? There have been some reports of the installer silently not extracting some files. I would reboot and test. If it persists, uninstall and reinstall Swift.

1 Like

SDKROOT is indeed set. Rebooting and reinstalling provided no help. But looking at it with fresh eyes this morning the spaces in my user name alerted my "this breaks toolchains" senses. Sure enough...

From an x64 developer command prompt: (If you're someone else trying this, you'll probably want to use "C:\swiftsdk" -- I just put it on my second drive as that's where my code lives.)

MKLINK /D D:\swiftsdk "%SDKROOT%"
SET SDKROOT=D:\swiftsdk

After that it appears to be working. I'm assuming that it's the spaces in my name that it's choking on, but it's also a heck of a lot shorter than the original SDKROOT, which is about 110 characters, so it could be bumping into MAXPATH, depending on what's being done with it.

At any rate, thanks for your help!

Ah, yes, that is a known issue (potentially a regression even). I believe that it has been filed as an issue, but it has been a bit and I don't remember if it was in swiftlang/swift or swift-lang/swift-driver). The issue is in the swift-driver where it is not properly quoting paths containing spaces.