The compiler error I get seems to relate to protoc-generated C++ code using
offsetof in a constexpr statement, but the MSVC-provided offsetof macro
uses reinterpret_cast.
In file included from .\writer.cpp:4:
In file included from ./addressbook.pb.h:26:
In file included from
C:\vcpkg\packages\protobuf_x64-windows\include\google/protobuf/generated_message_util.h:54:
In file included from
C:\vcpkg\packages\protobuf_x64-windows\include\google/protobuf/implicit_weak_message.h:39:
In file included from
C:\vcpkg\packages\protobuf_x64-windows\include\google/protobuf/repeated_field.h:60:
C:\vcpkg\packages\protobuf_x64-windows\include\google/protobuf/repeated_ptr_field.h(645,27):
error: constexpr variable
'kRepHeaderSize' must be initialized by a constant expression
static constexpr size_t kRepHeaderSize = offsetof(Rep, elements);
^ ~~~~~~~~~~~~~~~~~~~~~~~
C:\vcpkg\packages\protobuf_x64-windows\include\google/protobuf/repeated_ptr_field.h(645,44):
note: cast that performs
the conversions of a reinterpret_cast is not allowed in a constant
expression
static constexpr size_t kRepHeaderSize = offsetof(Rep, elements);
^
C:\Program Files (x86)\Windows
Kits\10\Include\10.0.19041.0\ucrt\stddef.h(47,32): note: expanded from
macro 'offsetof'
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const
volatile&>((((s*)0)->m)))
My environment:
- Windows 10, 64-bit
- Installed protobuf from vcpkg as per these instructions
<https://github.com/protocolbuffers/protobuf/blob/main/src/README.md#c-protobuf---windows>
(vcpkg install protobuf protobuf:x64-windows) (protoc.exe --version
reports 3.21.12)
- Installed latest LLVM toolchain from their releases
<https://github.com/llvm/llvm-project/releases> (LLVM-16.0.1-win64.exe)
- Installed Visual Studio 2022 (cl.exe version is 19.35.32215)
To reproduce:
1. Save this proto structure
<https://protobuf.dev/getting-started/cpptutorial/#protocol-format> as
addressbook.proto
2. Run C:\vcpkg\packages\protobuf_x64-windows\tools\protobuf\protoc.exe
--cpp_out=. addressbook.proto
3. Save this code
<https://protobuf.dev/getting-started/cpptutorial/#writing-a-message> as
writer.cpp
4. Run C:\Program Files\LLVM\bin\clang-cl.exe /std:c++20
'/IC:\vcpkg\packages\protobuf_x64-windows\include' -EHsc .\writer.cpp /MD
/link '/LIBPATH:C:\vcpkg\packages\protobuf_x64-windows\lib'
Is there a way to make the protoc.exe pre-compiled and distributed by vcpkg
to generate valid C++ output for this toolchain, or do I have to compile
protobuf myself to get this working? Not sure if this is a bug or an issue
with my use case.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/714082c5-912c-4a37-a901-224059cbbdd0n%40googlegroups.com.