Compiling a simple hello.swift on Windows

So I installed Swift on Windows and (after working around a bug in the installation instructions wrt. the file copying file names) tried to swiftc hello.swift. I get this:

C:\src\swift>swiftc -v hello.swift
compnerd.org Swift version 5.3 (swift-5.3-RELEASE)
Target: x86_64-unknown-windows-msvc
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe" -frontend -c -primary-file hello.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -color-diagnostics -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name hello -o "C:\\Users\\Z6SFG\\AppData\\Local\\Temp\\hello-fc422d.o"
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\clang.exe" -target x86_64-unknown-windows-msvc -nostartfiles -L "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\windows/x86_64" -L "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift/x86_64" "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\windows\\x86_64\\swiftrt.obj" "C:\\Users\\Z6SFG\\AppData\\Local\\Temp\\hello-fc422d.o" -I "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -v -o hello
compnerd.org clang version 10.0.0 (https://github.com/apple/llvm-project c39a810ec308dd4a8d93c5011fb73a5c987e8680)
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
clang: error: no such file or directory: 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64\swiftrt.obj'
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

And, sure enough, that file doesn't exist. In fact, the entire windows directory doesn't exist. Where did I go wrong? :slight_smile:

Did you install it via the toolchain.msi the one that has about 300MB?

It was around that size, but an exe: https://swift.org/builds/swift-5.3-release/windows10/swift-5.3-RELEASE/swift-5.3-RELEASE-windows10.exe

I "solved" it by first copying C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows into C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift, and then, when the next problem (can't open swiftSwiftOnoneSupport.lib) occured, by copying all .lib files in C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows into C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64. Something doesn't seem completely finished :stuck_out_tongue:

1 Like

I added the SWIFTFLAGS environmental variable with this content: "-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows"
And invoking swiftc main.swift -o lofasz.exe %SWIFTFLAGS% seems working after that.

2 Likes

Sounds good, I'll give it a try. Swiftc works now, but swift doesn't (maybe it's not supposed to. It seems to have trouble finding a lot of files.)

What files is it failing to find?

The expectation is as @cryo mentioned - to use the additional flags. Its not perfect, and I hope to improve that, but since most of the usage tends to be with build tooling, it was something that couldn't be fit into the initial release.

 D:\>swiftc main.swift -o lofasz.exe
clang: error: no such file or directory: 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64\swiftrt.obj'
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

D:\>swiftc main.swift -o lofasz.exe -v
compnerd.org Swift version 5.3 (swift-5.3-RELEASE)
Target: x86_64-unknown-windows-msvc
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe" -frontend -c -primary-file main.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -color-diagnostics -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name lofasz -o "C:\\Users\\GAJDOS~1\\AppData\\Local\\Temp\\main-42b045.o"
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\clang.exe" -target x86_64-unknown-windows-msvc -nostartfiles -L "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\windows/x86_64" -L "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift/x86_64" "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\windows\\x86_64\\swiftrt.obj" "C:\\Users\\GAJDOS~1\\AppData\\Local\\Temp\\main-42b045.o" -I "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -v -o lofasz.exe
compnerd.org clang version 10.0.0 (https://github.com/apple/llvm-project c39a810ec308dd4a8d93c5011fb73a5c987e8680)
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
clang: error: no such file or directory: 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64\swiftrt.obj'
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

D:\>swiftc main.swift -o lofasz.exe -v %SWIFTFLAGS%
compnerd.org Swift version 5.3 (swift-5.3-RELEASE)
Target: x86_64-unknown-windows-msvc
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe" -frontend -c -primary-file main.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -color-diagnostics -I "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk/usr/lib/swift" -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name lofasz -o "C:\\Users\\GAJDOS~1\\AppData\\Local\\Temp\\main-e80413.o"
"C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\clang.exe" -target x86_64-unknown-windows-msvc -nostartfiles -L "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift\\windows/x86_64" -L "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift/x86_64" "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift\\windows\\x86_64\\swiftrt.obj" "C:\\Users\\GAJDOS~1\\AppData\\Local\\Temp\\main-e80413.o" -I "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -L "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk/usr/lib/swift/windows" -v -o lofasz.exe
compnerd.org clang version 10.0.0 (https://github.com/apple/llvm-project c39a810ec308dd4a8d93c5011fb73a5c987e8680)
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\Hostx64\\x64\\link.exe" -out:lofasz.exe "-libpath:C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift\\windows/x86_64" "-libpath:C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift/x86_64" "-libpath:C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk/usr/lib/swift/windows" -nologo "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\usr\\lib\\swift\\windows\\x86_64\\swiftrt.obj" "C:\\Users\\GAJDOS~1\\AppData\\Local\\Temp\\main-e80413.o"
   Creating library lofasz.lib and object lofasz.exp

D:\>swift build main.swift
error: unable to invoke subcommand: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-build ()

D:\>

It is failing for me also.

Yes the reason that swift build is "failing" is that swift package manager didn't make it into the 5.3 release. There is more work to be done there, but there has been a fair amount of progress made on the current mainline branches.

I see, it is also a good progress. But what I miss is that the REPL environment also not launching when I issue swift command. It just gives back the prompt immediately.

That is a bug, I would appreciate it if you could file a JIRA issue for that. The REPL is supposed to work and be part of the release. We should be able to address the issue for the 5.3.1 release.

1 Like

Hi @compnerd,

First note that this is swift. It works with swiftc. Well it fails like this:

C:\src\swift>swift hello.swift
<unknown>:0: error: could not load the swift standard library

A more careful procmon.exe analysis (comparing it to swiftc) show it ending up failing to locate this file: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\swiftCore.dll. This file is present elsewhere in C:\Library, so copying it to the expected location makes it now fail like this instead (followed by 34 stack frames):

Assertion failed: StubOffset <= AllocationSize && "Not enough space allocated!", file D:\a\1\s\llvm-project\llvm\lib\ExecutionEngine\RuntimeDyld\RuntimeDyldImpl.h, line 110
Stack dump:
0.      Program arguments: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift.exe -frontend -interpret hello.swift -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -color-diagnostics -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name hello -- -o hello.exe

Same here

D:\>swift main.swift
<unknown>:0: error: could not load the swift standard library

D:\>swift main.swift %SWIFTFLAGS%
<unknown>:0: error: could not load the swift standard library

D:\>

I get the same message as well.

But see my (and other) comments above on how to get swiftc working, in case that doesn't work either. I don't know if swift is supposed to work or how to get it to work.

I had already followed your instructions (thanks!) and swiftc works.

That is the question, no sense filing bugs unless the behavior is unexpected.

swift is supposed to invoke the REPL. Unfortunately, a change was missed in the release cycle, which is resulting in the silent failure when swift is being invoked. That does deserve a JIRA report, which I've filed as SR-13596.

EDIT @gazsiazasz already had filed SR-13591 - using that to track this.

Yes, the REPL is supposed to work, but seems that there was some mix up and a patch got missed for the release (the functionality is working on mainline). I believe that we should be able to get this fixed with the 5.3.1 release.

3 Likes
Terms of Service

Privacy Policy

Cookie Policy