protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
64.59k stars 15.37k forks source link

Cannot link due to abseil_dll #17257

Open dpservis opened 2 weeks ago

dpservis commented 2 weeks ago

What version of protobuf and what language are you using? Version: 27.2 Language: C++

What operating system (Linux, Windows, ...) and version? Windows 11 What runtime / compiler are you using (e.g., python version or gcc version) VS2022 v143 What did you do? Steps to reproduce the behavior:

  1. Set cmake options image

  2. Build ALL_BUILD

What did you expect to see Build What did you see instead? 1>absl_base.lib(thread_identity.obj) : error LNK2005: "void cdecl absl::lts_20240116::base_internal::SetCurrentThreadIdentity(struct absl::lts_20240116::base_internal::ThreadIdentity *,void (cdecl)(void ))" (?SetCurrentThreadIdentity@base_internal@lts_20240116@absl@@YAXPEAUThreadIdentity@123@P6AXPEAX@Z@Z) already defined in abseil_dll.lib(abseil_dll.dll) 1>absl_base.lib(thread_identity.obj) : error LNK2005: "void __cdecl absl::lts_20240116::base_internal::ClearCurrentThreadIdentity(void)" (?ClearCurrentThreadIdentity@base_internal@lts_20240116@absl@@YAXXZ) already defined in abseil_dll.lib(abseil_dll.dll) Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

zhangskz commented 1 week ago

@mkruskal-google Can you take a look at if this needs a patch?

mkruskal-google commented 1 week ago

Can you provide the following information:

It looks like you're doing some kind of mix of static and dynamic linking, which is causing the conflicts. It's hard to tell with the information provided though.

dpservis commented 1 week ago
mkruskal-google commented 1 week ago

I'm able to build just fine using the cmake settings you showed through VS 2022. The thing I find strange is that the error you showed has references to abseil_dll.dll, which should not be built at all with those settings. You don't set BUILD_SHARED_LIBS or protobuf_BUILD_SHARED_LIBS, so everything should be statically linked. It could be leaking in through an earlier build with different settings or through a system installation of Abseil.

Without more complete logs there's not enough information here. I'm just asking for the full output (ideally with --verbose) that you copied that error snippet from.

dependon commented 1 week ago

I seem to have encountered the same problem as him. I compiled it in the main branch without modifying any options. I used version 7.3.0 of mingw32 for g++and gcc compilation, as well as version 3.26.3 of cmake, but encountered the following issues.

[ 57%] Building CXX object CMakeFiles/protoc.dir/src/google/protobuf/compiler/main.cc.obj [ 57%] Linking CXX executable protoc.exe libprotoc.a(names.cc.obj):names.cc:(.text+0x1419): undefined reference to std::allocator<absl::lts_20240116::string_view>::allocator()' libprotoc.a(names.cc.obj):names.cc:(.text+0x1be7): undefined reference tostd::allocator::allocator()' libprotoc.a(rust_keywords.cc.obj):rust_keywords.cc:(.text+0x255): undefined reference to std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocator()' libprotoc.a(rust_keywords.cc.obj):rust_keywords.cc:(.text+0x834): undefined reference tostd::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >::allocator()' libprotoc.a(csharp_helpers.cc.obj):csharp_helpers.cc:(.text+0x1864): undefined reference to `std::allocator::allocator()' collect2.exe: error: ld returned 1 exit status mingw32-make.exe[2]: [CMakeFiles\protoc.dir\build.make:188: protoc.exe] Error 1 mingw32-make.exe[1]: [CMakeFiles\Makefile2:1495: CMakeFiles/protoc.dir/all] Error 2 mingw32-make.exe: *** [Makefile:145: all] Error 2

image

mkruskal-google commented 4 days ago

That looks like a completely different problem, maybe file a separate issue?