Skip to content
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

[MSVC] GRPC failed to build due to error C2370: 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable': redefinition; different storage class #35297

Open
Zhaojun-Liu opened this issue Dec 13, 2023 · 8 comments
Assignees
Labels
disposition/help wanted Maintainers do not have enough resources to allocate to this at the moment. Help is appreciated! kind/bug lang/c++ priority/P2

Comments

@Zhaojun-Liu
Copy link

Zhaojun-Liu commented Dec 13, 2023

What version of gRPC and what language are you using?

GRPC commit we used : 12c0058
Language: c++

What operating system (Linux, Windows,...) and version?

Windows Server 2022 21H2

What runtime / compiler are you using (e.g. python version or version of gcc)

msvc

What did you do?

Repro steps:

  1. git clone https://github.com/grpc/grpc F:\gitP\grpc\grpc
  2. git -C "F:\gitP\grpc\grpc" reset --hard 12c0058
  3. git -C "F:\gitP\grpc\grpc" submodule sync
    git -C "F:\gitP\grpc\grpc" submodule foreach git reset --hard
    git -C "F:\gitP\grpc\grpc" submodule foreach git clean -xdf
    git -C "F:\gitP\grpc\grpc" submodule update --init --recursive
  4. set _CL_= /permissive-
  5. mkdir F:\gitP\grpc\grpc\build_amd64 & cd F:\gitP\grpc\grpc\build_amd64
  6. cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 ..
  7. msbuild /m /p:Platform=x64 /p:Configuration=Release grpc_cpp_plugin.vcxproj /t:Rebuild

What did you expect to see?

build pass without error.

What did you see instead?

F:\gitP\grpc\grpc\third_party\protobuf\src\google\protobuf\map_field.h(682,66): error C2370: 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable': redefinition; different storage class [F:\gitP\grpc\grpc\build_amd64\third_party\protobuf\libprotobuf.vcxproj]

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
detailed logs: build.log

Note:
If I remove the option /permissive-, it will build pass.

See TROUBLESHOOTING.md for how to diagnose problems better.

Anything else we should know about your project / environment?

@yashykt
Copy link
Member

yashykt commented Jan 2, 2024

I'm not sure what set _CL_= /permissive- does, but from the error, it looks like a protobuf error. Do you have any reason to believe that gRPC is doing something wrong here?

@Zhaojun-Liu
Copy link
Author

Zhaojun-Liu commented Jan 3, 2024

I'm not sure what set _CL_= /permissive- does, but from the error, it looks like a protobuf error. Do you have any reason to believe that gRPC is doing something wrong here?

set _CL_=/permissive- means add option /permissive- to the build process. You can find the detailed info here about this option.

I'm not sure if the root cause of this issue is a protobuf issue or a gRPC issue, but I built protobuf and it didn't have this error, it built pass. @yashykt

@JeySamir
Copy link

@Zhaojun-Liu I have the exact same error. Did you find a solution?

Z:\projects\cpp\network\mygrpc\external\grpc-src\third_party\protobuf\src\google/protobuf/map_field.h(682): error C2370: 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable': redefinition; different storage class

@Zhaojun-Liu
Copy link
Author

@Zhaojun-Liu I have the exact same error. Did you find a solution?

Z:\projects\cpp\network\mygrpc\external\grpc-src\third_party\protobuf\src\google/protobuf/map_field.h(682): error C2370: 'google::protobuf::internal::MapField<Derived,Key,T,kKeyFieldType_,kValueFieldType_>::kVTable': redefinition; different storage class

@JeySamir You can check if you build with option /permissive-, if yes, remove this option, it will build pass.

@yashykt yashykt added the disposition/help wanted Maintainers do not have enough resources to allocate to this at the moment. Help is appreciated! label Mar 12, 2024
@yashykt
Copy link
Member

yashykt commented Mar 12, 2024

If you are able to build protobuf and install without error with this option, could you try using -DgRPC_PROTOBUF_PROVIDER=package when building gRPC? This will find the installed protobuf library instead of using the submodule.

@Zhaojun-Liu
Copy link
Author

If you are able to build protobuf and install without error with this option, could you try using -DgRPC_PROTOBUF_PROVIDER=package when building gRPC? This will find the installed protobuf library instead of using the submodule.

@yashykt I tried to add -DgRPC_PROTOBUF_PROVIDER=package to
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 ..,
like below
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DgRPC_PROTOBUF_PROVIDER=package ..,
but cmake step failed due to "can't find protobuf", then I tried to install protobuf with vcpkg like
vcpkg install protobuf:x64-windows, protobuf installed successfully,
and then change cmake step to be
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DgRPC_PROTOBUF_PROVIDER=package -DCMAKE_TOOLCHAIN_FILE=F:\gitP\Microsoft\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..,
cmake step passed, but finally failed at
msbuild /m /p:Platform=x64 /p:Configuration=Release grpc_cpp_plugin.vcxproj /t:Rebuild
due to below errors:

F:\gitP\grpc\grpc\include\grpcpp\impl\codegen\config_protobuf.h(74,10): error C1083: Cannot open include file:
        'absl/status/status.h': No such file or directory (C:\repos\msvc\src\vctools\Compiler\CxxFE\sl\p1\c\p0prepro.c:
       2080) [F:\gitP\grpc\grpc\build_amd64\grpc_plugin_support.vcxproj]

Also, I tried the latest commit c910004 with the original steps, it still failed due to error C2370.

@yashykt
Copy link
Member

yashykt commented Mar 19, 2024

For -DgRPC_PROTOBUF_PROVIDER=package to work, protobuf should indeed be already installed.

I suspect that you are running into the same error with the absl dependency that you are running into with protobuf. Could you try the same thing with absl? i.e., install absl separately and specify -DgRPC_ABSL_PROVIDER=package.

Also, have you tried this with bazel?

@Zhaojun-Liu
Copy link
Author

For -DgRPC_PROTOBUF_PROVIDER=package to work, protobuf should indeed be already installed.

I suspect that you are running into the same error with the absl dependency that you are running into with protobuf. Could you try the same thing with absl? i.e., install absl separately and specify -DgRPC_ABSL_PROVIDER=package.

Also, have you tried this with bazel?
@yashykt I tried to istall protobuf and absl with command vcpkg install --recurse protobuf abseil --triplet x64-windows --clean-after-build
and then run cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ABSL_PROVIDER=package -DCMAKE_TOOLCHAIN_FILE=F:\gitP\Microsoft\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows .., and then msbuild /m /p:Platform=x64 /p:Configuration=Release grpc_cpp_plugin.vcxproj /t:Rebuild, it still failed, with following errors:
F:\gitP\grpc\grpc\src\compiler\config_protobuf.h(53,10): error C1083: Cannot open include file: 'google/protobuf/compiler/csharp/names.h': No such file or directory (C:\repos\msvc\src\vctools\Compiler\CxxFE\sl\p1\c\p0prepro.c:2080) [F:\gitP\grpc\grpc\build_amd64\grpc_plugin_support.vcxproj]

Also, how to build gRPC with bazel? Could you share some docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition/help wanted Maintainers do not have enough resources to allocate to this at the moment. Help is appreciated! kind/bug lang/c++ priority/P2
Projects
None yet
Development

No branches or pull requests

4 participants