Skip to content
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

Linking a simple swift program with a static library dependency fails. #249

Open
kcieplak opened this issue Mar 5, 2025 · 2 comments
Open

Comments

@kcieplak
Copy link
Contributor

kcieplak commented Mar 5, 2025

On windows a simple command link tool, that has a dependency on a static library fails to link.

LinkerTests.alternateLinkerSelection exposes this error and has to expect the error.

During the "Ld" task the linker fails to find the shared library.
LNK1181: cannot open input file 'Library.lib'

To reproduce
swift test --filter alternateLink

@kcieplak
Copy link
Contributor Author

kcieplak commented Mar 5, 2025

I have traced down the issue to the fact that we are creating the static library with a prefix of lib which is not how libraries are named in windows.

Using clang as the linker the -L Library is translated to a linker argument of "Library.lib"
However the the static library is named "libLibrary.lib"

AppData\Local\Temp\swbuild.tmp.40F9B78F-93B9-47FB-A592-0A6F98DFAD3D\Data.noindex\build\Debug-windows

2025-03-05  10:38 AM    <DIR>          .
2025-03-05  10:38 AM    <DIR>          ..
2025-03-05  10:38 AM    <DIR>          CommandLineTool.swiftmodule
2025-03-05  10:38 AM             3,472 libLibrary.lib
2025-03-05  10:38 AM    <DIR>          Library.swiftmodule

The fix is to set the EXECUTABLE_PREFIX to empty on the windows platform for static libraries.

Patch coming up shortly.

kcieplak added a commit to kcieplak/swift-build that referenced this issue Mar 5, 2025
Windows linking is failing to find a dependent
static library.

When using the clang driver for linking a '-l
Library' will be translated into an arguemnt of
'Library.lib'.

The linker is unable to find 'Library.lib'as the
static library is named 'libLibrary.lib'

* Remove the EXECUTABLE_PREFIX for static
libraries on the windows platform.
* Update the tests to not check for the link
  failures.
@kcieplak
Copy link
Contributor Author

kcieplak commented Mar 5, 2025

#250

owenv pushed a commit that referenced this issue Mar 6, 2025
Windows linking is failing to find a dependent
static library.

When using the clang driver for linking a '-l
Library' will be translated into an arguemnt of
'Library.lib'.

The linker is unable to find 'Library.lib'as the
static library is named 'libLibrary.lib'

* Remove the EXECUTABLE_PREFIX for static
libraries on the windows platform.
* Update the tests to not check for the link
  failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant