简体   繁体   English

Windows 上的 gRPC C++

[英]gRPC C++ on Windows

I have been trying for 3 days by now to find how to install and use gRPC on windows with no luck.我已经尝试了 3 天来寻找如何在 Windows 上安装和使用 gRPC 没有运气。 I am using Visual Studio 2015, Win7 64-bit.我使用的是 Visual Studio 2015,Win7 64 位。 To be safe, I'll write step by step of what I am doing.为了安全起见,我会一步一步地写我正在做的事情。 It might not be necessary but I am a beginner with C++ and with VS so I am not at all sure I am doing it correctly:这可能不是必需的,但我是 C++ 和 VS 的初学者,所以我完全不确定我是否正确执行此操作:

(following guide http://www.infopulse.com/blog/grpc-framework-by-google-tutorial/ ): (以下指南http://www.infopulse.com/blog/grpc-framework-by-google-tutorial/ ):

  • Get gRPC from git, init submodules从 git、init 子模块中获取 gRPC
  • Get gmock and gtest for protobuf (not in the guide, but else it doesn't work)为 protobuf 获取 gmock 和 gtest(不在指南中,否则它不起作用)
  • Run cmake on protobuf在 protobuf 上运行cmake
  • Build protobuf.sln in Visual Studio in Release mode (set for each part of the solution Property Manager > C/C++ > Code Generation > Runtime Library > /MDd )在 Visual Studio 中以 Release 模式构建protobuf.sln (为解决方案的每个部分设置 Property Manager > C/C++ > Code Generation > Runtime Library > /MDd
  • Copy Release/ folder to protobuf/cmake/ (instead of Debug/ as in intructions - that would give me libprotobufd.lib instead of libprotobuf.lib which is required)将 Release/ 文件夹复制到 protobuf/cmake/ (而不是说明中的 Debug/ - 这会给我libprotobufd.lib而不是libprotobuf.lib这是必需的)
  • Build grpc/vsprojects/grpc_protoc_plugins.sln in VS also in Release mode and again set for each part of the solution Property Manager > C/C++ > Code Generation > Runtime Library > /MDd在 VS 中以 Release 模式构建grpc/vsprojects/grpc_protoc_plugins.sln并再次为解决方案的每个部分设置 Property Manager > C/C++ > Code Generation > Runtime Library > /MDd
  • Copy protoc.exe from protobuf/cmake/Release to grpc/vsprojects/Release, which was created in previous stepprotoc.exe从protobuf/cmake/Release复制到上一步创建的grpc/vsprojects/Release
  • Build grpc/vsprojects/grpc.sln in VS in Debug mode (only the grpc++ part as I read somewhere and again set for each part of the solution Property Manager > C/C++ > Code Generation > Runtime Library > /MDd )在调试模式下在 VS 中构建grpc/vsprojects/grpc.sln (只有 grpc++ 部分,因为我在某处阅读并再次为解决方案的每个部分设置 Property Manager > C/C++ > Code Generation > Runtime Library > /MDd

So far things are going well.到目前为止,事情进展顺利。

  • Generate c files from proto in example folder.从示例文件夹中的 proto 生成 c 文件。 I get helloworld.grpc.pb.cc , helloworld.grpc.pb.h , helloworld.pb.cc and helloworld.pb.h and move them all to grpc/examples/cpp/helloworld:我得到helloworld.grpc.pb.cchelloworld.grpc.pb.hhelloworld.pb.cchelloworld.pb.h并将它们全部移动到 grpc/examples/cpp/helloworld :

    protoc --grpc_out=./hello_proto --plugin=protoc-gen-grpc=grpc_cpp_plugin.exe ../../examples/protos/helloworld.proto --proto_path=../../examples/protos protoc --grpc_out=./hello_proto --plugin=protoc-gen-grpc=grpc_cpp_plugin.exe ../../examples/protos/helloworld.proto --proto_path=../../examples/protos

    protoc --cpp_out=./hello_proto ../../examples/protos/helloworld.proto --proto_path=../../examples/protos protoc --cpp_out=./hello_proto ../../examples/protos/helloworld.proto --proto_path=../../examples/protos

  • I keep the grpc.sln open in VS and 'Add' > 'New Project'我在 VS 中保持grpc.sln打开并“添加”>“新建项目”

  • To the new project 'Add' > 'Existing Item' and add greeter_client.cc from grpc/examples/cpp到新项目 'Add' > 'Existing Item' 并从 grpc/examples/cpp 添加greeter_client.cc
  • Add dependencies as: https://github.com/grpc/grpc/issues/4707 , with Includes going in C/C++ > Additional Include Directories添加依赖项: https://github.com/grpc/grpc/issues/4707 ,包含进入 C/C++ > 附加包含目录

When I try to build my project errors are reported with not finding gflags, gtest, and libprotobuf.当我尝试构建我的项目时报告错误,没有找到 gflags、gtest 和 libprotobuf。 If I find it all and move them to an included folder, then I get these errors:如果我找到了所有内容并将它们移动到包含的文件夹中,则会出现以下错误:

    1>------ Build started: Project: greeter_client, Configuration: Debug Win32 ------
1>  greeter_client.cc
1>libprotobuf.lib(generated_message_util.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(generated_message_util.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libprotobuf.lib(common.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(common.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libprotobuf.lib(once.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(once.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libprotobuf.lib(status.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(status.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libprotobuf.lib(int128.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(int128.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libprotobuf.lib(atomicops_internals_x86_msvc.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libprotobuf.lib(atomicops_internals_x86_msvc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(client_context.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(insecure_credentials.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(create_channel.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(credentials.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(create_channel_internal.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(channel_arguments.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(core_codegen.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(codegen_init.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>grpc++.lib(status.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBE_JXZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __thiscall std::ios_base::width(__int64)" (?width@ios_base@std@@QAE_J_J@Z) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::widen(char)const " (?widen@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDD@Z) already defined in grpc++.lib(channel_arguments.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in libprotobuf.lib(status.obj)
1>msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in libprotobuf.lib(status.obj)
1>libcpmt.lib(ios.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(ios.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(locale0.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(locale0.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(locale0.obj) : error LNK2005: "void __cdecl std::_Facet_Register(class std::_Facet_base *)" (?_Facet_Register@std@@YAXPAV_Facet_base@1@@Z) already defined in msvcprtd.lib(locale0_implib.obj)
1>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(bool)" (?_Init@locale@std@@CAPAV_Locimp@12@_N@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@PBD@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(iosptrs.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(iosptrs.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(locale.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(locale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xlock.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(xlock.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(xthrow.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(xthrow.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xthrow.obj) : error LNK2005: "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc@std@@YAXXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(xthrow.obj) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(xthrow.obj) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(wlocale.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(wlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xlocale.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(xlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xdateord.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(xdateord.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(xwctomb.obj) : error LNK2005: __Getcvt already defined in msvcprtd.lib(MSVCP140D.dll)
1>libcpmt.lib(winapisupp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(winapisupp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(winapinls.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(winapinls.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(StlCompareStringW.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(StlCompareStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>libcpmt.lib(StlLCMapStringA.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in greeter_client.obj
1>libcpmt.lib(StlLCMapStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in greeter_client.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _deflate imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _deflateEnd imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _inflate imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _inflateEnd imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _deflateInit_ imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _inflateInit_ imported in function _BIO_f_zlib
1>libeay32.lib(c_zlib.obj) : warning LNK4217: locally defined symbol _zError imported in function _zlib_zfree
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: __thiscall helloworld::HelloRequest::HelloRequest(void)" (??0HelloRequest@helloworld@@QAE@XZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GreeterClient::SayHello(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SayHello@GreeterClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall helloworld::HelloRequest::~HelloRequest(void)" (??1HelloRequest@helloworld@@UAE@XZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GreeterClient::SayHello(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SayHello@GreeterClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: __thiscall helloworld::HelloReply::HelloReply(void)" (??0HelloReply@helloworld@@QAE@XZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GreeterClient::SayHello(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SayHello@GreeterClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall helloworld::HelloReply::~HelloReply(void)" (??1HelloReply@helloworld@@UAE@XZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GreeterClient::SayHello(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SayHello@GreeterClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: virtual class grpc::Status __thiscall helloworld::Greeter::Stub::SayHello(class grpc::ClientContext *,class helloworld::HelloRequest const &,class helloworld::HelloReply *)" (?SayHello@Stub@Greeter@helloworld@@UAE?AVStatus@grpc@@PAVClientContext@5@ABVHelloRequest@3@PAVHelloReply@3@@Z) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall GreeterClient::SayHello(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SayHello@GreeterClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
1>greeter_client.obj : error LNK2019: unresolved external symbol "public: static class std::unique_ptr<class helloworld::Greeter::Stub,struct std::default_delete<class helloworld::Greeter::Stub> > __cdecl helloworld::Greeter::NewStub(class std::shared_ptr<class grpc::ChannelInterface> const &,class grpc::StubOptions const &)" (?NewStub@Greeter@helloworld@@SA?AV?$unique_ptr@VStub@Greeter@helloworld@@U?$default_delete@VStub@Greeter@helloworld@@@std@@@std@@ABV?$shared_ptr@VChannelInterface@grpc@@@4@ABVStubOptions@grpc@@@Z) referenced in function "public: __thiscall GreeterClient::GreeterClient(class std::shared_ptr<class grpc::Channel>)" (??0GreeterClient@@QAE@V?$shared_ptr@VChannel@grpc@@@std@@@Z)
1>grpc++.lib(create_channel_internal.obj) : error LNK2019: unresolved external symbol "public: virtual __thiscall grpc::Channel::~Channel(void)" (??1Channel@grpc@@UAE@XZ) referenced in function "public: virtual void * __thiscall grpc::Channel::`scalar deleting destructor'(unsigned int)" (??_GChannel@grpc@@UAEPAXI@Z)
1>grpc++.lib(create_channel_internal.obj) : error LNK2019: unresolved external symbol "private: __thiscall grpc::Channel::Channel(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct grpc_channel *)" (??0Channel@grpc@@AAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUgrpc_channel@@@Z) referenced in function "class std::shared_ptr<class grpc::Channel> __cdecl grpc::CreateChannelInternal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct grpc_channel *)" (?CreateChannelInternal@grpc@@YA?AV?$shared_ptr@VChannel@grpc@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@PAUgrpc_channel@@@Z)
1>C:\Tool\C++gRPC\grpc\vsprojects\\Debug\gflagsd.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
1>C:\Tool\C++gRPC\grpc\vsprojects\Debug\greeter_client.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If anyone could offer a solution, I will be grateful.如果有人可以提供解决方案,我将不胜感激。

After struggling with various errors for many days, I found ready-to-install version here https://github.com/plasticbox/grpc-windows which seems to work satisfactory for my purpose.在与各种错误斗争了很多天之后,我在这里找到了准备安装的版本https://github.com/plasticbox/grpc-windows ,它似乎对我的目的很满意。 I post it here in case anyone is in similar situation.我把它贴在这里以防有人遇到类似的情况。

Update: June 2020更新:2020 年 6 月

According to the project page on GitHub the project is no longer maintained and therefore the example might not work any longer:根据 GitHub 上的项目页面,该项目不再维护,因此该示例可能不再起作用:

May 2019 NOTE: Project is no longer under active development, I definitely recommend using vcpkg 2019 年 5 月 注意:项目不再处于积极开发阶段,我绝对推荐使用 vcpkg

After struggling with this for some time myself, I found that vcpkg does a very good job building gRPC C++ for Windows.我自己为此苦苦挣扎了一段时间后,发现vcpkg在为 Windows 构建 gRPC C++方面做得非常好。 Note the requirements are Window 7 or later and VS2015 Update 3 or later.请注意,要求是 Window 7 或更高版本以及 VS2015 Update 3 或更高版本。 Note that you can configure it the way you want it by using a triplet, eg .\\vcpkg.exe install grpc --triplet x86-windows-static请注意,您可以使用三元组按您想要的方式配置它,例如 .\\vcpkg.exe install grpc --triplet x86-windows-static

Here is the solution I used to install and use grpc on windows...这是我用来在 Windows 上安装和使用 grpc 的解决方案......

GRPC C++... GRPC C++...
install...安装...
Microsoft Visual Studio Community 2017 Version 15.6.4 Microsoft Visual Studio 社区 2017 版本 15.6.4
Git吉特
CMake制作
Chocolatey巧克力味
Open git as admin以管理员身份打开 git
Active State Perl活动状态 Perl
choco install activeperl巧克力安装activeperl
Go
choco install golang巧克力安装golang
yasm亚斯姆
choco install yasm巧克力安装yasm
add C:\\ProgramData\\chocolatey\\lib\\yasm\\tools to PATH将 C:\\ProgramData\\chocolatey\\lib\\yasm\\tools 添加到 PATH
Ninja忍者
choco install ninja巧克力安装忍者
clone grpc sources including submodules...克隆 grpc 源,包括子模块...
git clone --recursive -b v1.10.x https://github.com/grpc/grpc git clone --recursive -b v1.10.x https://github.com/grpc/grpc
cd grpc光盘
cmake: Using Ninja (supports boringssl's assembly optimizations)... cmake:使用 Ninja(支持boringssl 的汇编优化)...
close git关闭 git
open Administrator: Command Prompt (shift+RC cmd and run as admin)打开管理员:命令提示符(shift+RC cmd 并以管理员身份运行)
cd C:\\Users\\aaron\\repo\\grpc cd C:\\用户\\aaron\\repo\\grpc
md .build && cd .build md .build && cd .build
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64调用“C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat”x64
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release cmake .. -GNinja -DCMAKE_BUILD_TYPE=发布
cmake --build . cmake --build 。
ninja install忍者安装

generating code...生成代码...
open visual studio and create new project打开视觉工作室并创建新项目
turn off precompiled headers关闭预编译头
RC project -> Properties -> C/C++ -> Precompiled Headers RC 项目 -> 属性 -> C/C++ -> 预编译头文件
Set Precompiled Header = "Not Using Precompiled Headers"设置预编译头=“不使用预编译头”
Delete stdafx.h/.cpp删除 stdafx.h/.cpp
add .proto file添加 .proto 文件
RC Resource Files -> Add new -> Utility -> Text.txt RC 资源文件 -> 添加新 -> 实用程序 -> Text.txt
name file with .proto extension带有 .proto 扩展名的文件名
write .proto file contents写入 .proto 文件内容
copy .proto to "C:\\Program Files (x86)\\grpc\\bin"将 .proto 复制到“C:\\Program Files (x86)\\grpc\\bin”
navigate to "C:\\Users\\aaron\\repo\\grpc\\.build"导航到“C:\\Users\\aaron\\repo\\grpc\\.build”
copy grpc_cpp_plugin.exe to "C:\\Program Files (x86)\\grpc\\bin"将 grpc_cpp_plugin.exe 复制到“C:\\Program Files (x86)\\grpc\\bin”
open Administrator: Command Prompt打开管理员:命令提示符
cd C:\\Program Files (x86)\\grpc\\bin cd C:\\Program Files (x86)\\grpc\\bin
protoc -I .协议 -I 。 --grpc_out=. --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin.exe cid_service.proto --plugin=protoc-gen-grpc=grpc_cpp_plugin.exe cid_service.proto
Generates cid_service.grpc.pb.cc/.h生成 cid_service.grpc.pb.cc/.h
protoc -I .协议 -I 。 --cpp_out=. --cpp_out=. cid_service.proto cid_service.proto
Generates cid_service.pb.cc/.h生成 cid_service.pb.cc/.h
copy files to VS project and add them to Header Files/Source Files将文件复制到 VS 项目并将它们添加到头文件/源文件

In order to install gRPC using vcpkg, launch a console in Windows and execute the following command,为了使用 vcpkg 安装 gRPC,在 Windows 中启动一个控制台并执行以下命令,

  1. vcpkg install grpc:x64-windows
  2. vcpkg install protobuf protobuf:x64-windows
  3. vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows
  4. vcpkg integrate install

Now we have everything we need, so let's try to generate the message and service interfaces from a proto file using the protoc compiler现在我们拥有了我们需要的一切,所以让我们尝试使用 protoc 编译器从 proto 文件生成消息和服务接口

If protoc is not available from your console, you might have to add it to your system env PATH.如果 protoc 在您的控制台中不可用,您可能需要将它添加到您的系统环境 PATH 中。 And it will be present in your <vcpkg_install_path>\\packages\\protobuf_x64-windows\\tools\\protobuf folder它将出现在您的<vcpkg_install_path>\\packages\\protobuf_x64-windows\\tools\\protobuf文件夹中

Now copy the file to our project/proto folder and run the following commands from there现在将文件复制到我们的 project/proto 文件夹并从那里运行以下命令

  1. protoc -I=. --cpp_out=. <yourprotofile>.proto

  2. protoc -I=. --grpc_out=. --plugin=protoc-gen-grpc="<vcpkg_install_path>\\packages\\grpc_x64-windows\\tools\\grpc\\grpc_cpp_plugin.exe" <your_protofile>.proto

Now let's add content to our CMakeLists.txt file.现在让我们向 CMakeLists.txt 文件添加内容。 Take the following code and copy it to our CMakeLists.txt file.将以下代码复制到我们的 CMakeLists.txt 文件中。

//  start  //

cmake_minimum_required( VERSION 3.1 )

project( grpc_example )

find_package(gRPC CONFIG REQUIRED)

find_package( Protobuf REQUIRED )


include_directories(<vcpkg_install_path>/buildtrees/protobuf/src/23fa7edd52-3ba2225d30.clean/src)

add_executable( server src/server.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)

add_executable( client src/client.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)

target_link_libraries( server PRIVATE gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )

target_link_libraries( client PRIVATE gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )

// end //

Now go to our project/build folder and issue the following command to generate a project using CMake.现在转到我们的 project/build 文件夹并发出以下命令以使用 CMake 生成一个项目。 I'll be generating a Visual Studio 2015 solution here, but the choice is up to you.我将在此处生成 Visual Studio 2015 解决方案,但选择权取决于您。

  1. cmake -G "Visual Studio 14 2015 Win64" ../ -DCMAKE_TOOLCHAIN_FILE=<vcpkg_install_path>/scripts/buildsystems/vcpkg.cmake
  2. cmake build .
  3. cmake --build . --config Release

Now go to the Release folder, and run the server.exe and client.exe现在转到 Release 文件夹,并运行 server.exe 和 client.exe

This helped a lot thank you for making this.这很有帮助,谢谢你做这个。 I used this by extracting the zip, cd in the folder and with我通过在文件夹中解压缩 zip、cd 并使用它来使用它

git clone -b v1.2.0 https://github.com/grpc/grpc

git submodule update --init

Install pthreads to visual studios VC\\include(.h), lib(.lib) and bin(.dll)将 pthreads 安装到 Visual Studios VC\\include(.h)、lib(.lib) 和 bin(.dll)

run nuget restore (foreach .sln file to get dependencies)运行 nuget restore(foreach .sln 文件以获取依赖项)

nuget restore grpc\vsprojects\grpc.sln

nuget restore grpc\vsprojects\grpc_protoc_plugins.sln

nuget restore grpc\third_party\protobuf\cmake\build\solution\protobuf.sln

Fix grpc\\src\\cpp\\server\\ server_builder.cc修复 grpc\\src\\cpp\\server\\ server_builder.cc

int num_frequently_polled_cqs = sync_server_cqs->size();

Change int to size_t in line 273, int num...(as above)在第 273 行中将 int 更改为 size_t,int num...(如上)

Run grpc_build.bat, next goto grpc_helloworld folder and run test_protoc.bat, open grpc_helloworld.sln, running build should execute nuget automatically.运行grpc_build.bat,接下来进入grpc_helloworld文件夹并运行test_protoc.bat,打开grpc_helloworld.sln,运行build应该会自动执行nuget。

Please see my answer to a similar question on SO.请参阅我对 SO 上类似问题的回答

It describes in detail how to get, build, install and use gRPC on Windows with Visual Studio.它详细描述了如何使用 Visual Studio 在 Windows 上获取、构建、安装和使用 gRPC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM