-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
constexpr redefinition errors when compiling Protocol Buffers generated code with Visual Studio 2022 and Protocol Buffers v29.3 #20100
Comments
Would you mind posting (you can omit/replace field names if you want):
|
I have resolved the initial issue, but I am currently facing 500 linking errors related to the Abseil library. Specifically, I am encountering the following unresolved external symbol error: |
What cmake flags are you using? We have a dependency on abseil, so you might need to link in that as well |
Would you mind sharing what was the issue and how you solved it? |
I followed the instructions to create a solution for Visual Studio and subsequently compiled the libraries. Currently, I am using only libprotobufd.lib, libprotobuf_lited.lib, and protocd.lib. I also tried linking the Abseil libraries, but I was wondering if that is the right approach or if I made any mistakes. If not, which Abseil libraries should I add to the linker |
The errors were related to constexpr functions in the file.pb.cc file, which contained expressions that could not be evaluated at compile time. I resolved the issue by modifying the file.pb.cc file to make the problematic expressions evaluable during compilation. |
What part of the expression was wrong, and how did you fix it? |
I solved the linking error by linking this list of static libraries: absl_str_format_internal.lib |
I resolved an error in C++20 related to the PROTOBUF_FIELD_OFFSET macro in the following code: constexpr auto arena_bits = ::google::protobuf::internal::EncodePlacementArenaOffsets({ To fix the issue, I replaced the PROTOBUF_FIELD_OFFSET macro with the standard offsetof macro, which is allowed in constant expressions and evaluates to a constexpr value. After the change, the code looks like this: constexpr auto arena_bits = ::google::protobuf::internal::EncodePlacementArenaOffsets({ |
I resolved an error in C++20 that occurred in the following code: using HasBits = decltype(std::declval().impl.has_bits); To resolve the issue, I replaced static constexpr with inline const, which relaxes the requirement for compile-time evaluation while still allowing the constant to be defined with internal linkage and avoiding unnecessary memory usage. Here's the updated code: using HasBits = decltype(std::declval().impl.has_bits); |
I resolved an error in the following code that uses the ::google::protobuf::internal::memswap function: ::google::protobuf::internal::memswap< To resolve this issue, I created my own memswap function, which manually swaps the contents of two memory regions using a temporary buffer. Here's the function I implemented: inline void memswap(char* a, char* b, size_t size) {
} Copy the content of a into the temporary buffer. |
I encountered multiple errors while compiling the code generated by Protocol Buffers v29.3 using Visual Studio 2022. The errors point to constexpr redefinition issues and other problems with functions being marked as constexpr. Below is the exact error message:
RiskUnitProtocol.pb.cc
1>C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(10553,15): error C2475: 'RiskUnitProtocol::Drivers::InternalNewImpl_': redefinition; different 'constexpr' specifiers
1> C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.h(10937,25):
1> see declaration of 'RiskUnitProtocol::Drivers::InternalNewImpl_'
1>C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(10553,15): error C3615: constexpr function 'RiskUnitProtocol::Drivers::InternalNewImpl_' cannot return a constant expression
1> C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(10553,15):
1> failure was caused by reaching the end of a constexpr function
1>C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(16780,41): error C2475: 'RiskUnitProtocol::VistaturaSecondoLivello::InternalNewImpl_': redefinition; different 'constexpr' specifiers
1> C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.h(512,15):
1> see declaration of 'RiskUnitProtocol::VistaturaSecondoLivello::InternalNewImpl_'
1>C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(19031,19): error C2475: 'RiskUnitProtocol::Simulazioni::InternalNewImpl_': redefinition; different 'constexpr' specifiers
1> C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.h(7997,25):
1> see declaration of 'RiskUnitProtocol::Simulazioni::InternalNewImpl_'
1>C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(19031,19): error C3615: constexpr function 'RiskUnitProtocol::Simulazioni::InternalNewImpl_' cannot return a constant expression
1> C:\Users\mgorla\Documents\alicanto\QPosition_Risk\QPosition_Risk\RiskUnitProtocol.pb.cc(19031,19):
1> failure was caused by reaching the end of a constexpr function
Environment:
Protocol Buffers version: v29.2
Compiler: Visual Studio 2022
Operating System: Windows 1\
The text was updated successfully, but these errors were encountered: