protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

[MSVC] When building Google_Protobuf emits error C2338 on MSVC

Open Apriltanq opened this issue 3 years ago • 5 comments

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:

  1. open VS2019 x64 tools command
  2. git clone https://github.com/google/protobuf F:\gitP\google\protobuf\build_x86
  3. set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=x86 -arch=x86
  4. set originalLIB=%LIB%
  5. set LIB=/MACHINE:X86 %orignalLIB%
  6. cd F:\gitP\google\protobuf\build_x86
  7. 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

Google build.txt

Apriltanq avatar Mar 03 '22 07:03 Apriltanq

Are you still seeing this issue? What version of protobuf are you using and what architecture is this being run on?

deannagarcia avatar Jul 12 '22 18:07 deannagarcia

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

Zhaojun-Liu avatar Jul 15 '22 02:07 Zhaojun-Liu

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?

fowles avatar Jul 15 '22 03:07 fowles

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?

We use Visual C++ Compiler and Visual Studio 2019 to build the protobuf and under x86 mode.

Zhaojun-Liu avatar Jul 15 '22 03:07 Zhaojun-Liu

Any fixes? It's okay if you can provide a workarounds for us.

QuellaZhang avatar Jul 25 '22 06:07 QuellaZhang

Hi @fowles, Is there some update on this issue? Thanks.

Zhaojun-Liu avatar Aug 22 '22 08:08 Zhaojun-Liu

I need you to make a tiny program with the same build flags and output sizeof(void*) and alignof(void*)

fowles avatar Aug 22 '22 13:08 fowles

Hi @fowles, I want to update some info.

Repro steps:

  1. git clone https://github.com/google/protobuf F:\gitP\google\protobuf
  2. mkdir F:\gitP\google\protobuf\build_x86 and cd F:\gitP\google\protobuf\build_x86
  3. cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0.18362.0 ..\cmake
  4. set LIB=/MACHINE:X86
  5. open an x86 Native Tools Command Prompt for VS
  6. 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.

Zhaojun-Liu avatar Aug 23 '22 07:08 Zhaojun-Liu

just to clarify this is a 32 bit windows build, yes?

fowles avatar Aug 23 '22 14:08 fowles

just to clarify this is a 32 bit windows build, yes?

yes

Zhaojun-Liu avatar Aug 24 '22 01:08 Zhaojun-Liu

Is this only a problem in extension_set_unittest.cc? Or have you seen this error in non test files?

sbenzaquen avatar Aug 29 '22 14:08 sbenzaquen

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)

QuellaZhang avatar Aug 30 '22 09:08 QuellaZhang

Hi @sbenzaquen @jorgbrown, Any update of this issue?

Zhaojun-Liu avatar Sep 08 '22 06:09 Zhaojun-Liu

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.

mapogu avatar Sep 10 '22 05:09 mapogu

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.

pianocomp81 avatar Mar 13 '23 16:03 pianocomp81

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.

fowles avatar Mar 13 '23 16:03 fowles

OK, thanks. I'll see what I can do locally, or if I can update to v22.x

pianocomp81 avatar Mar 13 '23 17:03 pianocomp81