首页 > 解决方案 > 为什么我不能将 gRPC 链接到我的静态库中?

问题描述

我已经编译了带有所有依赖项(Protobuf、a-arec 等)的 gRPC 1.23.0。

将我的.proto文件翻译成*.grpc.pb.**.pb.*文件后,我将其添加到 VS 项目并成功将其编译为.exe文件。

但是在我将Configuration type属性切换到Dynamic libraryor之后Static library(我真的需要完全Static library),它编译没有错误,但是在链接步骤中Build output我看到 >2000 链接警告是这样的:

1>grpc++_unsecure.lib(pb_encode.obj) : warning LNK4006: _pb_encode_submessage already defined in grpc++.lib(pb_encode.obj); second definition ignored
1>grpc++_unsecure.lib(pb_encode.obj) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>grpc++_unsecure.lib(codegen_init.obj) : warning LNK4006: "class grpc::CoreCodegenInterface * grpc::g_core_codegen_interface" (?g_core_codegen_interface@grpc@@3PAVCoreCodegenInterface@1@A) already defined in grpc++.lib(codegen_init.obj); second definition ignored
1>grpc++_unsecure.lib(codegen_init.obj) : warning LNK4006: "class grpc::GrpcLibraryInterface * grpc::g_glip" (?g_glip@grpc@@3PAVGrpcLibraryInterface@1@A) already defined in grpc++.lib(codegen_init.obj); second definition ignored
1>grpc++_unsecure.lib(codegen_init.obj) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>grpc_unsecure.lib(init.obj) : warning LNK4006: _grpc_register_plugin already defined in grpc.lib(init.obj); second definition ignored
1>grpc_unsecure.lib(init.obj) : warning LNK4006: _grpc_init already defined in grpc.lib(init.obj); second definition ignored
1>grpc_unsecure.lib(init.obj) : warning LNK4006: _grpc_shutdown already defined in grpc.lib(init.obj); second definition ignored
1>grpc_unsecure.lib(init.obj) : warning LNK4006: _grpc_is_initialized already defined in grpc.lib(init.obj); second definition ignored

最后链接以错误结束:

1>libprotobufd.lib(version.res) : fatal error LNK1241: resource file libprotocd.lib(version.res) already specified

此错误仅在Debug配置时出现。就它链接成功,但也有Release链接警告。

我应该怎么做才能解决它?

标签: c++protocol-buffersgrpc

解决方案


推荐阅读