Windows Setup Issues

I'm having an "on again off again" relationship with Windows. Having this same issue on both of my machines and I have no idea why I'm getting link errors. I've gone over the setup process multiple times and did a full Visual Studio removal and reinstall.

C:\Test>swift --version
compnerd.org Swift version 5.4-dev (LLVM 798a505f5bc4a05, Swift 7f7978370b08812)
Target: x86_64-unknown-windows-msvc

C:\Test>swift package init
Creating library package: Test
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources\Test\Test.swift
Creating Tests/
Creating Tests\TestTests/
Creating Tests\TestTests\TestTests.swift

C:\Test>swift build --product Test
C:\Test: error: manifest parse error(s):
lld-link: error: <root>: undefined symbol: mainCRTStartup
lld-link: error: undefined symbol: memcpy
>>> referenced by C:\Users\dustb\AppData\Local\Temp\Package-b6f103.o:($s18PackageDescription6TargetC10DependencyOWOb)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

C:\Test>echo %SDKROOT%
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk

C:\Test>echo %UniversalCRTSdkDir%
C:\Program Files (x86)\Windows Kits\10\

C:\Test>echo %VCToolsInstallDir%
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\

Here's my visual studio setup:

Any ideas?

Alright, so these link errors don't happen in one of my complex packages with multiple library dependencies and an parent executable with basic main()

But if I create a new library package with no dependencies I get both mainCRTStartup and memcpy link errors.
And if I make it an executable package with no dependencies I only get the mainCRTStartup link error.
I assume the errors are undefined symbol errors.

As stated above, with a complex package including an executable everything builds fine. I wasn't able to figure out exactly what needs to be referenced for the linker to succeed.

I also get the link errors when building @compnerd's DirectX example. So I assume my environment is not properly setup, but I've wiped visual studio and started clean with no luck.

I'm itching to get back to work though and since my project currently builds I'm just gonna go with it for now.

Interesting. I know that there can be issues if you are not in the developer command prompt (and it must be the x64 native developer command prompt). The reason for that is the library search path environment variables needed are setup by the DevEnv.cmd script. Do you have an example package that demonstrates the build failure and steps to reproduce it? I've not been able to figure out how to reproduce such a failure. The missing symbols can happen due to mismatches on the architecture.

:expressionless:
Yup that's it, the command prompt I was using was the x86. Using the x64 everything works.
My complex package worked because I was using VSCode to build it.

I didn't realize there were 2 native tools command prompts... I just assumed if it said native tools then I was all set. Thanks!

2 Likes
Terms of Service

Privacy Policy

Cookie Policy