Skip to content

Duplicate main symbol for swift test on Windows #6367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
remko opened this issue Apr 2, 2023 · 7 comments · Fixed by #8515
Closed

Duplicate main symbol for swift test on Windows #6367

remko opened this issue Apr 2, 2023 · 7 comments · Fixed by #8515
Labels
bug swift test Changes impacting `swift test` tool windows

Comments

@remko
Copy link

remko commented Apr 2, 2023

Description

I have a package with an executable target, and a test target. The tests in the test target do a @testable import of the executable target. The main target has a @main struct ....

Running swift test works on macOS and Linux.
Running swift test on Windows fails.

Expected behavior

When running swift test on Windows, the tests run.

Actual behavior

When running swift test on windows, it fails with an error at link time:

lld-link: error: duplicate symbol: main
>>> defined at C:\\...\\MyPackageTests.build\\runner.swift.o
>>> defined at C:\\...\\MyPackage\\MyMainStruct.swift.o

Steps to reproduce

No response

Swift Package Manager version/commit hash

version included in the official Swift download for Windows

Swift & OS version (output of swift --version && uname -a)

Swift: 5.8
OS: Microsoft Windows Server 2022

(also happens on other versions of swift and OS).

@remko remko added the bug label Apr 2, 2023
@neonichu
Copy link
Contributor

neonichu commented Apr 3, 2023

Sounds as if -entry-point-function-name is maybe not working correctly on Windows? We could disable the feature via BuildParameters.canRenameEntrypointFunctionName if it doesn't work there.

cc @compnerd

@compnerd
Copy link
Member

compnerd commented Apr 3, 2023

@neonichu that definitely works: https://github.com/compnerd/swift-win32-application/blob/main/Package.swift even has an example. The problem is that you cannot alias functions using the linker on Windows and this needs to be done in SPM.

@compnerd
Copy link
Member

I think that I have a solution to this that is cross-platform as long as we are reliant on LLVM! The symbol rewriter should do this properly on all file formats!

@dabrahams
Copy link
Contributor

dabrahams commented Dec 29, 2023

Oof; I should have searched for this before creating the minimal reproducer. But there it is in case it helps! Be sure you get the spm-bug-windows-test-executable-dependency tag.

@grynspan
Copy link
Contributor

grynspan commented May 1, 2024

@MaxDesiatov Do you think this issue would be resolved now with your cross-compilation macros work?

@compnerd
Copy link
Member

compnerd commented May 4, 2024

I'm still seeing it recently with swift-foundation at least.

JosephDuffy added a commit to JosephDuffy/HashableMacro that referenced this issue May 27, 2024
This may not work and still be blocked by swiftlang/swift-package-manager#6367.

Would close #5.
@grynspan grynspan added the swift test Changes impacting `swift test` tool label Jul 24, 2024
@jakepetroules jakepetroules marked this as a duplicate of #6083 Apr 17, 2025
jakepetroules added a commit that referenced this issue Apr 17, 2025
This uses the /ALTERNATENAME flag to link.exe, which is roughly equivalent to -alias/--defsym. This has been verified to work in a sample project.

See https://devblogs.microsoft.com/oldnewthing/20200731-00/ for more info.

Closes #6367
jakepetroules added a commit that referenced this issue Apr 18, 2025
This uses the /ALTERNATENAME flag to link.exe, which is roughly equivalent to -alias/--defsym. This has been verified to work in a sample project.

See https://devblogs.microsoft.com/oldnewthing/20200731-00/ for more info.

Closes #6367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug swift test Changes impacting `swift test` tool windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants