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

DLL name stripping support for libraries created by GCC in Windows #21280

Closed
wants to merge 0 commits into from
Closed

Conversation

vvviktor
Copy link
Contributor

@vvviktor vvviktor commented Feb 9, 2024

Fixes #9696
.dll has to be stripped to enable linkage with DLL created by GCC in Windows

@vvviktor vvviktor requested a review from lberki as a code owner February 9, 2024 19:32
@github-actions github-actions bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Feb 9, 2024
@vvviktor vvviktor changed the title DLL stripping support for libraries created by GCC in Windows DLL name stripping support for libraries created by GCC in Windows Feb 9, 2024
@vvviktor vvviktor marked this pull request as draft February 9, 2024 21:36
@vvviktor vvviktor marked this pull request as ready for review February 9, 2024 21:37
@vvviktor
Copy link
Contributor Author

vvviktor commented Feb 10, 2024

This case was successfully tested :

Workspace structure:

D:.
│   .bazelrc
│   BUILD
│   MODULE.bazel
│   MODULE.bazel.lock
│   WORKSPACE
│
├───Main
│       BUILD
│       main.cpp
│       math.cpp
│       math.h
│       math_dll_interface.cpp
│       math_dll_interface.h
│       math_import_defs.h
│
└───toolchain
        BUILD
        toolchain_config.bzl

BUILD file:

# //Main/BUILD

DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"]

cc_binary(
    name = "sum_numbers_mingw",
    srcs = ["main.cpp"],
    deps = [":math_d_shared"]
)

cc_import(
    name = "math_d_shared",
    hdrs = DLL_HDRS,
    shared_library = ":libmath_d.dll"
)

cc_binary(
    name = "libmath_d.dll",
    srcs = ["math_dll_interface.cpp"] + DLL_HDRS,
    deps = [":math"],
    defines = ["MATH_DLL"],
    linkshared = 1
)

cc_library(
    name = "math",
    srcs = ["math.cpp"],
    hdrs = ["math.h"],
    copts = ["-std=c++17"]
)

Without patch applied bazel build //main:sum_numbers_mingw --verbose_failures fails with error:
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmath_d.dll: No such file or directory
Then after patch was applied it builds all targets as expected.

This approach also works fine with patch applied:

# //Main/BUILD

DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"]

cc_binary(
    name = "sum_numbers_mingw",
    srcs = ["main.cpp"] + DLL_HDRS,
    dynamic_deps = [":math_d_shared"]
)

cc_shared_library(
    name = "math_d_shared",
    shared_lib_name = "libmath_d.dll",
    deps = [":math_dll_interface"]
)

cc_library(
    name = "math_dll_interface",
    srcs = ["math_dll_interface.cpp"],
    hdrs = DLL_HDRS,
    deps = [":math"],
    defines = ["MATH_DLL"]
)

cc_library(
    name = "math",
    srcs = ["math.cpp"],
    hdrs = ["math.h"],
    copts = ["-std=c++17"]
)

@vvviktor vvviktor closed this Feb 18, 2024
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linking fails for library name contains .dll suffix
1 participant