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
[SR-14728] SwiftPM/Driver on Windows fails to link C-based targets #4415
Comments
cc @compnerd |
CC: @abertelrud This is caused by using |
@swift-ci create |
Just adding this for people who stumble upon the issue. I don't have a solution for this in mind, but do have a temporary workaround that users can use: -Xlinker %SDKROOT%\usr\lib\swift\windows\x86_64\swiftCore.lib This is a rather unsatisfactory workaround as it causes a preserved over-linkage to the swift runtime which will cause an extra module constructor to be invoked. |
For stumblers again, a perhaps less-sketchy workaround is to put the C code in a library and invoke it from a trivial Swift main. HTH! |
And if you want it to work with Xcode; that's slightly too trivial; you need to use |
Attachment: Download
Environment
OS: Windows 10 Pro (20H2)
Toolchain: compnerd.org Swift version 5.5-dev (LLVM 76b16fe31111aa0, Swift 5eb25f1662051fd)
Additional Detail from JIRA
md5: a5cefba8ea42e9bae4dfc9028530df2a
Issue Description:
When using SPM on Windows to build a `.dynamic` library which only contains C targets, the linker fails with the following error:
Running `swift build -Xswiftc -v` reveals what seems to be the issue:
i.e. the Swift driver appears to be linking swiftrt.obj but not swiftCore.lib (since swift-autolink-extract sees no need for swiftCore.lib because it's a pure C target). Using the driver by itself (instead of through swift build) also produces this issue.
I'm not too familiar with the Swift codebase but an initial search seems to indicate that the issue is caused due to swiftrt.obj being unconditionally linked at lib/Driver/WindowsToolChains.cpp#L134. Running `swift build -Xswiftc -lswiftCore` causes it to link successfully – though I suspect that not linking swiftrt.obj in C-only targets might be the preferred solution.
I've attached a minimal project demonstrating the issue; running `swift build` succeeds on both macOS and Linux, but fails on Windows.
The text was updated successfully, but these errors were encountered: