Using a fresh installation of Swift on Windows: `stdint.h not found`

Context

Hi all, I am currently attempting to install Swift on a Windows laptop (with pretty close to a fresh installation of Windows).

I followed the installation instructions at Swift.org and they completed successfully (with one slight modification). Here are the exact commands that I ran (I had to change the python version from 3.7.8 to 3.7.8150.0 because otherwise the command failed stating that version 3.7.8 does not exist):

winget install Git.Git
winget install Python.Python.3 --version 3.7.8150.0

curl -sOL https://aka.ms/vs/16/release/vs_community.exe
start /w vs_community.exe --passive --wait --norestart --nocache ^
  --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
  --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64
del /q vs_community.exe

winget install Swift.Toolchain

Once installed, I ran the following commands to create a new executable package:

mkdir HelloWorld
cd HelloWorld
swift package init --type=executable

Issue

My issue is that when I attempt to build the package with swift build, I get the following errors:

C:\Users\User\Documents\Swift\HelloWorld>swift build
warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
C:\Users\User\Documents\Swift\HelloWorld: error: manifest parse error(s):
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "AssertionReporting.h"
          ^
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\AssertionReporting.h:16:10: note: in file included from C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\AssertionReporting.h:16:
#include "SwiftStdint.h"
          ^
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\SwiftStdint.h:28:10: error: 'stdint.h' file not found
#include <stdint.h>
          ^
<unknown>:0: error: could not build C module 'SwiftShims' 

The same error also occurs if I create a swift file containing print("Hello, world!") and try compiling it with swiftc file.swift.

Another error that might be important is the error that I get if I try to run anything in the swift repl:

C:\Users\User\Documents\Swift\HelloWorld>swift
Welcome to compnerd.org Swift version 5.5 (swift-5.5-RELEASE).
Type :help for assistance.
1> print("Hello, world!")
Assertion failed: false && "called into swift language runtime stub", file D:\a\1\s\llvm-project\lldb\source\Plugins\LanguageRuntime\Swift\SwiftLanguageRuntime.cpp, line 368
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
 #0 0x00007ff6d010e5d5 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe+0x1e5d5)
 #1 0x00007ffb60d8caad (C:\WINDOWS\System32\ucrtbase.dll+0x6caad)
 #2 0x00007ffb60d8dab1 (C:\WINDOWS\System32\ucrtbase.dll+0x6dab1)
 #3 0x00007ffb60d8f4ee (C:\WINDOWS\System32\ucrtbase.dll+0x6f4ee)
 #4 0x00007ffb60d8f3e5 (C:\WINDOWS\System32\ucrtbase.dll+0x6f3e5)
 #5 0x00007ffb60d8f771 (C:\WINDOWS\System32\ucrtbase.dll+0x6f771)
 #6 0x00007ffae3db556c PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x82556c)
 #7 0x00007ffae89a7774 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5417774)
 #8 0x00007ffae89acff3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541cff3)
 #9 0x00007ffae89aa6e8 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541a6e8)
#10 0x00007ffae89a4b36 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5414b36)
#11 0x00007ffae3ade4a3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x54e4a3)
#12 0x00007ffae3aeca9b PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x55ca9b)
#13 0x00007ffae3abac46 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x52ac46)
#14 0x00007ffae3a6960a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d960a)
#15 0x00007ffae3a6832e PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d832e)
#16 0x00007ffb60d410b2 (C:\WINDOWS\System32\ucrtbase.dll+0x210b2)
#17 0x00007ffb61f37c24 (C:\WINDOWS\System32\KERNEL32.DLL+0x17c24)
#18 0x00007ffb62e6d721 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6d721)

Attempted solutions

In the past I have run into the same issue. From memory, I solved it by installing a certain version of Visual Studio and installing all of the c and cpp components available in that version (I just trial and errored a bunch of different versions, can't remember which one worked). iirc I also had to copy some headers from the Visual Studio SDK to the Swift toolchain to get it working correctly.

But that took me quite a while to get working (slow computer) and given that this is a fresh install of Swift on basically a fresh install of Windows (I've only installed a few essential apps so far) my thinking is that there might be something simple that I am missing which @compnerd and co might be able to help with.

Any help would be greatly appreciated

Are you using x64 Native Tools Command Prompt?

No, I just followed the installation instructions and then ran swift build in command prompt.

I can’t find the native tools command prompt, but I did find the developer command prompt after installing vs (vs 2019 as per the installation instructions). And I got the same error.

The installation instructions don’t even install the developer command prompt (it only installs a few specific visual studio components and native tools isn’t one of them). So I’m assuming that means that it is expected to work without the developer cmd prompt?

How about install this component additionally:

vs_community --add Microsoft.VisualStudio.Component.VC.CoreBuildTools

Not currently. I’m working on that, but it still takes time to use Swift from regular command prompt. x64 Native Tools Command Prompt is still required now, and it seems to be missing in the setup.

After running that command it seems that it just installed another copy of the developer command prompt and no native tools cmd prompt.

Ah ok, it might worth updating the setup instructions once we figure out what the issue with my installation is.

I don’t use Windows very often, but it would be great if it were easier to setup Swift so that there is less of a barrier for developers looking to add Windows support to their packages. So thanks for working on making the Windows Swift experience better, and good luck!

Could you please verify if you have the C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat file on your machine?

The "Native Developer Command Prompt" changes the name across versions. The original instructions are still accurate and correct. Make sure that system indexing is working as it may not immediately show up in the windows search - there is nothing that we can do about that. Additionally make sure that you install Swift after you install Visual Studio. If you installed them out-of-order, you will need to repair the Swift installation (you should be able to go to the "Add Remove Programs" control panel and repair it from there).

From the error, it seems that you changed the order of installation as the missing files are not deployed. The REPL is known to not work out of the box, that is a regression introduced in 5.3 but no one has stepped up to help fix it.

With 5.5 onwards, you should be able to use swift in a regular command prompt without having to worry about the Native Developer Command Prompt.

Ok, so before running the following commands from the installation instructions what should I install? I assumed that the installation instructions installed all required dependencies because it does install git, python and the two parts of vs code required I think.

winget install Git.Git
winget install Python.Python.3 --version 3.7.8

curl -sOL https://aka.ms/vs/16/release/vs_community.exe
start /w vs_community.exe --passive --wait --norestart --nocache ^
  --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
  --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64
del /q vs_community.exe

winget install Swift.Toolchain

Those are the exact steps I followed. And I installed Swift 5.5.3, which should work without a special command prompt right?

Oh, and additionally, I had to install python 3.7.8150.0 because apparently 3.7.8 doesnt exist in winget’s world. Is that supposed to happen?

That should install all the necessary dependencies.

Did you have an installation of Visual Studio (any version at all) before running any of the commands? Did you run the installer prior to this point? The instructions assume a clean install of windows with no software installed after the installation of windows. Did you run the commands in cmd or power shell?

I ran the commands in cmd prompt, and before running the commands it was essentially a clean install of Windows. I had installed some apps before trying to install swift, but nothing developer related.

Great, and can you verify that visual studio actually did complete the installation? You should have C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Tools\MSVC\19.??.?????\Include.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\ does exist, but the Tools directory isn't present. The directories that are there are Common7, Licenses, MSBuild, Team Tools and Xml.

  --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

should have installed that. It seems that the component is missing. I would suggest that you go into "Add Remove Programs" and select Visual Studio to run the Visual Studio Installer and ensure that the "MSVC x86/x64 build tools (Latest)" is selected. The docs for VS2019 are gone, but its roughly similar to Visual Studio Community workload and component IDs | Microsoft Docs with some minor differences in the display name.

I have completely deleted Visual Studio from the computer (somewhere along the way troubleshooting I seem to have installed both enterprise and community). And I've installed it again as per the installation instructions for Swift.

I still can't see the C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Tools\MSVC\19.??.?????\Include directory you mentioned earlier, however, I did find C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include.

When I open the installer I can confirm that the two components installed are MSVC v142 - VS 2019 C++ x64/x86 build tools (Latest) and Windows 10 SDK (10.0.19041.0)

I am currently in the process of reinstalling Swift, and while waiting I noticed that native tools now seems to be installed. I don't know what I did differently this time. But I'll report back whether the new installation works from within native tools once it has installed

Some things seem to be working now! Below I've reported on which things still are and aren't working in command prompt and the native tools command prompt separately

Command prompt

swift build of a basic executable package:

warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
The system cannot find the path specified.
[0/0] Build complete!
warning: unable to create symbolic link at C:\Users\stackotter\Documents\Swift\HelloWorld\.build\debug: Error Domain=NSCocoaErrorDomain Code=256 "(null)"

swiftc test.swift where test.swift is a program that prints hello world:

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)

repl:

1> print("Hello, world!")
Assertion failed: false && "called into swift language runtime stub", file D:\a\1\s\llvm-project\lldb\source\Plugins\LanguageRuntime\Swift\SwiftLanguageRuntime.cpp, line 368
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
 #0 0x00007ff63664e5d5 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe+0x1e5d5)
 #1 0x00007ff80760caad (C:\WINDOWS\System32\ucrtbase.dll+0x6caad)
 #2 0x00007ff80760dab1 (C:\WINDOWS\System32\ucrtbase.dll+0x6dab1)
 #3 0x00007ff80760f4ee (C:\WINDOWS\System32\ucrtbase.dll+0x6f4ee)
 #4 0x00007ff80760f3e5 (C:\WINDOWS\System32\ucrtbase.dll+0x6f3e5)
 #5 0x00007ff80760f771 (C:\WINDOWS\System32\ucrtbase.dll+0x6f771)
 #6 0x00007fff8ba3556c PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x82556c)
 #7 0x00007fff90627774 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5417774)
 #8 0x00007fff9062cff3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541cff3)
 #9 0x00007fff9062a6e8 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541a6e8)
#10 0x00007fff90624b36 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5414b36)
#11 0x00007fff8b75e4a3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x54e4a3)
#12 0x00007fff8b76ca9b PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x55ca9b)
#13 0x00007fff8b73ac46 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x52ac46)
#14 0x00007fff8b6e960a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d960a)
#15 0x00007fff8b6e832e PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d832e)
#16 0x00007ff8075c10b2 (C:\WINDOWS\System32\ucrtbase.dll+0x210b2)
#17 0x00007ff808d87c24 (C:\WINDOWS\System32\KERNEL32.DLL+0x17c24)
#18 0x00007ff80a14d721 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6d721)

Native tools command prompt

swift run of a basic executable package (it works!!):

warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
warning: Failed creating default cache locations, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
[1/1] Planning build
The system cannot find the path specified.
[0/0] Build complete!
warning: unable to create symbolic link at C:\Users\stackotter\Documents\Swift\HelloWorld\.build\debug: Error Domain=NSCocoaErrorDomain Code=256 "(null)"
Hello, world!

swiftc test.swift where test.swift is a program that prints hello world:

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)

repl:

1> print("Hello")
Assertion failed: false && "called into swift language runtime stub", file D:\a\1\s\llvm-project\lldb\source\Plugins\LanguageRuntime\Swift\SwiftLanguageRuntime.cpp, line 368
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
 #0 0x00007ff63664e5d5 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe+0x1e5d5)
 #1 0x00007ff80760caad (C:\WINDOWS\System32\ucrtbase.dll+0x6caad)
 #2 0x00007ff80760dab1 (C:\WINDOWS\System32\ucrtbase.dll+0x6dab1)
 #3 0x00007ff80760f4ee (C:\WINDOWS\System32\ucrtbase.dll+0x6f4ee)
 #4 0x00007ff80760f3e5 (C:\WINDOWS\System32\ucrtbase.dll+0x6f3e5)
 #5 0x00007ff80760f771 (C:\WINDOWS\System32\ucrtbase.dll+0x6f771)
 #6 0x00007fff8ba3556c PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x82556c)
 #7 0x00007fff90627774 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5417774)
 #8 0x00007fff9062cff3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541cff3)
 #9 0x00007fff9062a6e8 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x541a6e8)
#10 0x00007fff90624b36 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x5414b36)
#11 0x00007fff8b75e4a3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x54e4a3)
#12 0x00007fff8b76ca9b PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x55ca9b)
#13 0x00007fff8b73ac46 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x52ac46)
#14 0x00007fff8b6e960a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d960a)
#15 0x00007fff8b6e832e PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4d832e)
#16 0x00007ff8075c10b2 (C:\WINDOWS\System32\ucrtbase.dll+0x210b2)
#17 0x00007ff808d87c24 (C:\WINDOWS\System32\KERNEL32.DLL+0x17c24)
#18 0x00007ff80a14d721 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6d721)

Installing support files

I noticed that there is a section in the installation instructions that claims it is not necessary for Swift versions after 5.4.2, however, after following them swift build now works in the regular command prompt as well.

It seems like Swift 5.5.3 still only works if it is used from the native tools command prompt or the support files are copied. Well, by works I mean that swift build works. swiftc doesn't seem to work either way.

Conclusion

It's great that I can finally build swift packages now, I don't really know why that didn't work in the first place, the visual studio installer must've done something weird (because native tools wasn't there at all).

However, swiftc still doesn't work (and neither does the repl but I don't really care about that).

Swift 5.5 installer can copy these files so you don’t need to do this manually. That’s why you need to install Swift after VS.

You need to append -sdk %SDKROOT% to make it work. I know this is not ideal, and someday the restriction will go away. If you’re compiling an executable, append -emit-executable -o <name>.exe. SwiftPM will just handle these flags for you.

1 Like

I installed Swift after VS and those files didnt seem to get copied, I had to do it manually. Swift version is 5.5. I installed through winget like in the installation instructions.

Okay thanks, that’s good to know