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

[Bug]: Linker error with boost.program_options and boost.uuid on Windows #3278

Open
Vertexwahn opened this issue Nov 27, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Vertexwahn
Copy link
Contributor

Vertexwahn commented Nov 27, 2024

What happened?

Minimal Demo to reproduce linker errors:

cli.cpp:

#include "boost/uuid/uuid.hpp"
#include "boost/uuid/uuid_generators.hpp"
#include "boost/uuid/uuid_io.hpp"

int main() {
    boost::uuids::random_generator gen;
    boost::uuids::uuid id = gen();

    return 0;
}

BUILD.bazel:

cc_binary(
    name = "cli",
    srcs = ["cli.cpp"],
    deps = [
        "@boost.program_options//:boost.program_options",
        "@boost.uuid//:boost.uuid",
    ],
)

MODULE.bazel:

bazel_dep(name = "boost.uuid", version = "1.83.0.bcr.1")
bazel_dep(name = "boost.program_options", version = "1.83.0.bcr.1")

.bazelversion:

7.4.1

Build on Windows via bazel build //... gives:

ERROR: C:/dev/BUILD.bazel:1:10: Linking cli.exe failed: (Exit 1120): link.exe failed: error executing CppLink command (from target //:cli) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\HostX64\x64\link.exe @bazel-out/x64_windows-fastbuild/bin/cli.exe-2.params
cli.obj : error LNK2019: unresolved external symbol BCryptCloseAlgorithmProvider referenced in function "private: void __cdecl boost::uuids::detail::random_provider_base::destroy(void)" (?destroy@random_provider_base@detail@uuids@boost@@AEAAXXZ)   
cli.obj : error LNK2019: unresolved external symbol BCryptGenRandom referenced in function "public: void __cdecl boost::uuids::detail::random_provider_base::get_random_bytes(void *,unsigned __int64)" (?get_random_bytes@random_provider_base@detail@uuids@boost@@QEAAXPEAX_K@Z)
cli.obj : error LNK2019: unresolved external symbol BCryptOpenAlgorithmProvider referenced in function "public: __cdecl boost::uuids::detail::random_provider_base::random_provider_base(void)" (??0random_provider_base@detail@uuids@boost@@QEAA@XZ)   
bazel-out\x64_windows-fastbuild\bin\cli.exe : fatal error LNK1120: 3 unresolved externals
Target //:cli failed to build                                                                                               
Use --verbose_failures to see the command lines of failed build steps.   

Adding

    linkopts = select({
        "@platforms//os:windows": ["-defaultlib:bcrypt.lib"],
        "//conditions:default": [],
    }),

to boost.uuid resolves the linker error - but that seems not to be the root cause, since removing the "@boost.program_options//:boost.program_options", dependencies solves the issue... (see #3278)

Maybe defines = ["BOOST_ALL_NO_LIB"], is the root cause here

Version

Development (host) and target OS/architectures:
Windows 10 x64

Output of bazel --version:
bazel 7.4.1

Version of relevant rules from the WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:
C++20, Boost 1.83.0

How to reproduce

see abouve

Any other information?

No response

@Vertexwahn Vertexwahn added the bug Something isn't working label Nov 27, 2024
@Vertexwahn
Copy link
Contributor Author

@wep21 Maybe you have an idea...

@Vertexwahn
Copy link
Contributor Author

@wep21

If I change the program cli.cpp to:

#undef BOOST_ALL_NO_LIB  // with this extension no compile error happens

#include "boost/uuid/uuid.hpp"
#include "boost/uuid/uuid_generators.hpp"
#include "boost/uuid/uuid_io.hpp"

int main() {
    boost::uuids::random_generator gen;
    boost::uuids::uuid id = gen();

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant