[MSVC] When building Google_Protobuf emits error C2338 on MSVC
Hi, all Google_Protobuf fails to build on MSVC build main_20220223.01 due to error C2338. Could you please help look at this issue? Thank you very much.
What version of protobuf and what language are you using? Version: 29b3d01
What operating system (Linux, Windows, ...) and version? Window 10
What runtime / compiler are you using (e.g., python version or gcc version) git
What did you do? Steps to reproduce the behavior:
- open VS2019 x64 tools command
- git clone https://github.com/google/protobuf F:\gitP\google\protobuf\build_x86
- set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=x86 -arch=x86
- set originalLIB=%LIB%
- set LIB=/MACHINE:X86 %orignalLIB%
- cd F:\gitP\google\protobuf\build_x86
- msbuild /p:Platform=Win32 /p:Configuration=Release protobuf.sln /t:Rebuild 2>&1
What did you expect to see Compile fine. What did you see instead? F:\gitP\google\protobuf\src\google/protobuf/repeated_field.h(81,27): error C2338: static_assert failed: '' (compiling source file F:\gitP\google\protobuf\src\google\protobuf\extension_set_unittest.cc) [F:\gitP\google\protobuf\build_x86\tests.vcxproj] Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Build log
Are you still seeing this issue? What version of protobuf are you using and what architecture is this being run on?
Hi @deannagarcia I met the same issue. The commit of protobuf we use now is c38281dd20e562bac239bc77ab2fa10f71661708 The Visual Studio version is vs2019(VS16.11.11), OS is Windows Server 2019, it reports error C2338 on x86 mode. You can check the details in the attached log file. Could you please help look this issue? Thanks. build.log
I am deeply confused by this error. Tracing through the various static asserts it seems like the only way this can fail is if sizeof(void*) == 8 but alignof(void*) == 4. Do you happen to know what those are for that compiler and platform?
I am deeply confused by this error. Tracing through the various static asserts it seems like the only way this can fail is if
sizeof(void*) == 8butalignof(void*) == 4. Do you happen to know what those are for that compiler and platform?
We use Visual C++ Compiler and Visual Studio 2019 to build the protobuf and under x86 mode.
Any fixes? It's okay if you can provide a workarounds for us.
Hi @fowles, Is there some update on this issue? Thanks.
I need you to make a tiny program with the same build flags and output sizeof(void*) and alignof(void*)
Hi @fowles, I want to update some info.
Repro steps:
- git clone https://github.com/google/protobuf F:\gitP\google\protobuf
- mkdir F:\gitP\google\protobuf\build_x86 and cd F:\gitP\google\protobuf\build_x86
- cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0.18362.0 ..\cmake
- set LIB=/MACHINE:X86
- open an x86 Native Tools Command Prompt for VS
- msbuild /p:Platform=Win32 /p:Configuration=Release protobuf.sln /t:Rebuild
The step 6 also can be: Open "F:\gitP\google\protobuf\build_x86\tests.vcxproj" with VS2019 (v16.11.18) and then right click the project and select [Rebuild]
The commit of Google_Protobuf we used is: a972626551cc1e6ab425b880ab0c2bb006ae2251
I attached a full preprocessed .i file extension_set_unittest.zip
To repro the issue with the .i file, my command is: (open an x86 native tools command prompt for vs) cl.exe extension_set_unittest.i /TP /EHsc
Note: Under x64 mode, it built ok.
Hope the above helps. Thanks.
just to clarify this is a 32 bit windows build, yes?
just to clarify this is a 32 bit windows build, yes?
yes
Is this only a problem in extension_set_unittest.cc? Or have you seen this error in non test files?
Yes, only repeated_field.h file emits an error when compiling extension_set_unittest.cc file.
F:\gitP\google\protobuf\src\google/protobuf/repeated_field.h(81,27): error C2338: static_assert failed: '' (compiling source file F:\gitP\google\protobuf\src\google\protobuf\extension_set_unittest.cc)
Hi @sbenzaquen @jorgbrown, Any update of this issue?
I got the same issue running cmake running om v3.21.5 cmake ../ -G"Visual Studio 17 2022" -A WIN32 .....
It looks like version v3.18.1 is compiling the unit tests successfully on windows x86. There is a commit which changed the unit test ( ab4585a695 ) which was included in v3.18.2. I ofc don't know if it is related but maybe this helps you find the issue.
How easily could this be ported to the v21.x branch? I'm building Linux 32-bit against the v21.12 tag right now (using the "-m32" GCC option), and running into the exact same problem.
I could try doing it myself, but have never been in the protobuf code before today.
Honestly, it is kind of a pain to port the tests back to 21.x. We recently redid our testing system to be much faster and more reliable, but it did not get migrated back to <=21.x releases.
OK, thanks. I'll see what I can do locally, or if I can update to v22.x