c++ - 无法在 VS2015 中正确链接 Google Protobuf

标签 c++ protocol-buffers

我花了几天时间尝试获取 C++ 应用程序,但我陷入了库/dll 进程,我对这两个应用程序有问题。

我下载了 protobuf 3.0.0 的 C++ 版本,制作了 .lib 和 .dll(以测试它们两个),我使用它来获取 .sln

cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="../install" ../cmake

它给了我一个解决方案,我用 vs2015 打开并编译进行调试,然后编译文件,然后使用提供的 .bat 生成包含文件。

所以,当我转到 VS2015 并尝试使用链接的 .lib 进行编译时,它给了我这个错误

1>libprotobufd.lib(dynamic_message.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj

我确信我在库构建中运行应用程序作为调试,并且游戏也作为调试运行。

此外,我尝试了 .dll(删除库和引用),在 main.cpp 文件的顶部写入“#define PROTOBUF_USE_DLLS”,并且出现了很多这样的链接器错误

1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: __thiscall google::protobuf::internal::LogMessage::LogMessage(enum google::protobuf::LogLevel,char const *,int)" (??0LogMessage@internal@protobuf@google@@QAE@W4LogLevel@23@PBDH@Z) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: __thiscall google::protobuf::internal::LogMessage::~LogMessage(void)" (??1LogMessage@internal@protobuf@google@@QAE@XZ) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: class google::protobuf::internal::LogMessage & __thiscall google::protobuf::internal::LogMessage::operator<<(char const *)" (??6LogMessage@internal@protobuf@google@@QAEAAV0123@PBD@Z) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: void __thiscall google::protobuf::internal::LogFinisher::operator=(class google::protobuf::internal::LogMessage &)" (??4LogFinisher@internal@protobuf@google@@QAEXAAVLogMessage@123@@Z) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall google::protobuf::Closure::~Closure(void)" (??1Closure@protobuf@google@@UAE@XZ) referenced in function "public: virtual void * __thiscall google::protobuf::Closure::`scalar deleting destructor'(unsigned int)" (??_GClosure@protobuf@google@@UAEPAXI@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall google::protobuf::internal::FunctionClosure0::~FunctionClosure0(void)" (??1FunctionClosure0@internal@protobuf@google@@UAE@XZ) referenced in function "public: virtual void * __thiscall google::protobuf::internal::FunctionClosure0::`scalar deleting destructor'(unsigned int)" (??_GFunctionClosure0@internal@protobuf@google@@UAEPAXI@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "void __cdecl google::protobuf::internal::VerifyVersion(int,int,char const *)" (?VerifyVersion@internal@protobuf@google@@YAXHHPBD@Z) referenced in function "void __cdecl tryPhy::protobuf_AddDesc_trycpp_2eproto(void)" (?protobuf_AddDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "void __cdecl google::protobuf::internal::OnShutdown(void (__cdecl*)(void))" (?OnShutdown@internal@protobuf@google@@YAXP6AXXZ@Z) referenced in function "void __cdecl tryPhy::protobuf_AddDesc_trycpp_2eproto(void)" (?protobuf_AddDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: void * __thiscall google::protobuf::Arena::AllocateAligned(class type_info const *,unsigned int)" (?AllocateAligned@Arena@protobuf@google@@QAEPAXPBVtype_info@@I@Z) referenced in function "public: struct google::protobuf::internal::InternalMetadataWithArena::Container * __thiscall google::protobuf::Arena::CreateInternal<struct google::protobuf::internal::InternalMetadataWithArena::Container>(bool)" (??$CreateInternal@UContainer@InternalMetadataWithArena@internal@protobuf@google@@@Arena@protobuf@google@@QAEPAUContainer@InternalMetadataWithArena@internal@12@_N@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: void __thiscall google::protobuf::Arena::AddListNode(void *,void (__cdecl*)(void *))" (?AddListNode@Arena@protobuf@google@@QAEXPAXP6AX0@Z@Z) referenced in function "public: struct google::protobuf::internal::InternalMetadataWithArena::Container * __thiscall google::protobuf::Arena::CreateInternal<struct google::protobuf::internal::InternalMetadataWithArena::Container>(bool)" (??$CreateInternal@UContainer@InternalMetadataWithArena@internal@protobuf@google@@@Arena@protobuf@google@@QAEPAUContainer@InternalMetadataWithArena@internal@12@_N@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "void __cdecl google::protobuf::GoogleOnceInitImpl(int *,class google::protobuf::Closure *)" (?GoogleOnceInitImpl@protobuf@google@@YAXPAHPAVClosure@12@@Z) referenced in function "void __cdecl google::protobuf::GoogleOnceInit(int *,void (__cdecl*)(void))" (?GoogleOnceInit@protobuf@google@@YAXPAHP6AXXZ@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "void __cdecl google::protobuf::internal::MergeFromFail(char const *,int)" (?MergeFromFail@internal@protobuf@google@@YAXPBDH@Z) referenced in function "public: void __thiscall tryPhy::PhyData::MergeFrom(class tryPhy::PhyData const &)" (?MergeFrom@PhyData@tryPhy@@QAEXABV12@@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "private: void __thiscall google::protobuf::UnknownFieldSet::ClearFallback(void)" (?ClearFallback@UnknownFieldSet@protobuf@google@@AAEXXZ) referenced in function "public: void __thiscall google::protobuf::UnknownFieldSet::Clear(void)" (?Clear@UnknownFieldSet@protobuf@google@@QAEXXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual class google::protobuf::MessageLite * __thiscall google::protobuf::MessageLite::New(class google::protobuf::Arena *)const " (?New@MessageLite@protobuf@google@@UBEPAV123@PAVArena@23@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall google::protobuf::MessageLite::InitializationErrorString(void)const " (?InitializationErrorString@MessageLite@protobuf@google@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual unsigned char * __thiscall google::protobuf::MessageLite::InternalSerializeWithCachedSizesToArray(bool,unsigned char *)const " (?InternalSerializeWithCachedSizesToArray@MessageLite@protobuf@google@@UBEPAE_NPAE@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static class google::protobuf::DescriptorPool const * __cdecl google::protobuf::DescriptorPool::generated_pool(void)" (?generated_pool@DescriptorPool@protobuf@google@@SAPBV123@XZ) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: class google::protobuf::FileDescriptor const * __thiscall google::protobuf::DescriptorPool::FindFileByName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?FindFileByName@DescriptorPool@protobuf@google@@QBEPBVFileDescriptor@23@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static void __cdecl google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const *,int)" (?InternalAddGeneratedFile@DescriptorPool@protobuf@google@@SAXPBXH@Z) referenced in function "void __cdecl tryPhy::protobuf_AddDesc_trycpp_2eproto(void)" (?protobuf_AddDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::CopyFrom(class google::protobuf::Message const &)" (?CopyFrom@Message@protobuf@google@@UAEXABV123@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::MergeFrom(class google::protobuf::Message const &)" (?MergeFrom@Message@protobuf@google@@UAEXABV123@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall google::protobuf::Message::InitializationErrorString(void)const " (?InitializationErrorString@Message@protobuf@google@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::DiscardUnknownFields(void)" (?DiscardUnknownFields@Message@protobuf@google@@UAEXXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall google::protobuf::Message::SpaceUsed(void)const " (?SpaceUsed@Message@protobuf@google@@UBEHXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall google::protobuf::Message::GetTypeName(void)const " (?GetTypeName@Message@protobuf@google@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::Clear(void)" (?Clear@Message@protobuf@google@@UAEXXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall google::protobuf::Message::IsInitialized(void)const " (?IsInitialized@Message@protobuf@google@@UBE_NXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::CheckTypeAndMergeFrom(class google::protobuf::MessageLite const &)" (?CheckTypeAndMergeFrom@Message@protobuf@google@@UAEXABVMessageLite@23@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall google::protobuf::Message::MergePartialFromCodedStream(class google::protobuf::io::CodedInputStream *)" (?MergePartialFromCodedStream@Message@protobuf@google@@UAE_NPAVCodedInputStream@io@23@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall google::protobuf::Message::ByteSize(void)const " (?ByteSize@Message@protobuf@google@@UBEHXZ)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall google::protobuf::Message::SerializeWithCachedSizes(class google::protobuf::io::CodedOutputStream *)const " (?SerializeWithCachedSizes@Message@protobuf@google@@UBEXPAVCodedOutputStream@io@23@@Z)
1>trycpp.pb.obj : error LNK2001: unresolved external symbol "private: virtual void __thiscall google::protobuf::Message::SetCachedSize(int)const " (?SetCachedSize@Message@protobuf@google@@EBEXH@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static void __cdecl google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const *,void (__cdecl*)(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &))" (?InternalRegisterGeneratedFile@MessageFactory@protobuf@google@@SAXPBDP6AXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@Z) referenced in function "void __cdecl tryPhy::protobuf_AddDesc_trycpp_2eproto(void)" (?protobuf_AddDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static void __cdecl google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(class google::protobuf::Descriptor const *,class google::protobuf::Message const *)" (?InternalRegisterGeneratedMessage@MessageFactory@protobuf@google@@SAXPBVDescriptor@23@PBVMessage@23@@Z) referenced in function "void __cdecl tryPhy::`anonymous namespace'::protobuf_RegisterTypes(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?protobuf_RegisterTypes@?A0x859c682f@tryPhy@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "private: bool __thiscall google::protobuf::io::CodedInputStream::ReadLittleEndian64Fallback(unsigned __int64 *)" (?ReadLittleEndian64Fallback@CodedInputStream@io@protobuf@google@@AAE_NPA_K@Z) referenced in function "public: bool __thiscall google::protobuf::io::CodedInputStream::ReadLittleEndian64(unsigned __int64 *)" (?ReadLittleEndian64@CodedInputStream@io@protobuf@google@@QAE_NPA_K@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "private: unsigned int __thiscall google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)" (?ReadTagFallback@CodedInputStream@io@protobuf@google@@AAEII@Z) referenced in function "public: struct std::pair<unsigned int,bool> __thiscall google::protobuf::io::CodedInputStream::ReadTagWithCutoff(unsigned int)" (?ReadTagWithCutoff@CodedInputStream@io@protobuf@google@@QAE?AU?$pair@I_N@std@@I@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl google::protobuf::internal::WireFormatLite::SkipField(class google::protobuf::io::CodedInputStream *,unsigned int)" (?SkipField@WireFormatLite@internal@protobuf@google@@SA_NPAVCodedInputStream@io@34@I@Z) referenced in function "public: virtual bool __thiscall tryPhy::PhyData::MergePartialFromCodedStream(class google::protobuf::io::CodedInputStream *)" (?MergePartialFromCodedStream@PhyData@tryPhy@@UAE_NPAVCodedInputStream@io@protobuf@google@@@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static void __cdecl google::protobuf::internal::WireFormatLite::WriteDouble(int,double,class google::protobuf::io::CodedOutputStream *)" (?WriteDouble@WireFormatLite@internal@protobuf@google@@SAXHNPAVCodedOutputStream@io@34@@Z) referenced in function "public: virtual void __thiscall tryPhy::PhyData::SerializeWithCachedSizes(class google::protobuf::io::CodedOutputStream *)const " (?SerializeWithCachedSizes@PhyData@tryPhy@@UBEXPAVCodedOutputStream@io@protobuf@google@@@Z)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static class google::protobuf::internal::GeneratedMessageReflection * __cdecl google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(class google::protobuf::Descriptor const *,class google::protobuf::Message const *,int const * const,int,int,int,int,int,int)" (?NewGeneratedMessageReflection@GeneratedMessageReflection@internal@protobuf@google@@SAPAV1234@PBVDescriptor@34@PBVMessage@34@QBHHHHHHH@Z) referenced in function "void __cdecl tryPhy::protobuf_AssignDesc_trycpp_2eproto(void)" (?protobuf_AssignDesc_trycpp_2eproto@tryPhy@@YAXXZ)
1>trycpp.pb.obj : error LNK2019: unresolved external symbol "public: static void __cdecl google::protobuf::internal::ReflectionOps::Merge(class google::protobuf::Message const &,class google::protobuf::Message *)" (?Merge@ReflectionOps@internal@protobuf@google@@SAXABVMessage@34@PAV534@@Z) referenced in function "public: virtual void __thiscall tryPhy::PhyData::MergeFrom(class google::protobuf::Message const &)" (?MergeFrom@PhyData@tryPhy@@UAEXABVMessage@protobuf@google@@@Z)
1>bin\windows\multiplayer.exe : fatal error LNK1120: 40 unresolved externals

我有点迷失和卡住了,所以如果有人可以帮助我重定向我必须搜索的位置,我将不胜感激。

感谢您的宝贵时间

最佳答案

由于我无法发表评论,因此将其作为答案发布。 如果我正确理解了你的项目的结构,这个东西:

`1>libprotobufd.lib(dynamic_message.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj`

告诉您,您尝试链接的库的运行时库设置与您的项目不匹配。 检查项目属性 -> C/C++ -> 代码生成 -> 运行时库并确保两个项目的此设置相同。

附注在 vs2015 update 3 中链接包含原始文件的静态库也有问题,但似乎你的情况有所不同..

关于c++ - 无法在 VS2015 中正确链接 Google Protobuf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40683319/

相关文章:

c++ - ByteSize() 方法的复杂性

c++ - 使用 VS2017 为 Linux 构建 protobuf

java - 使用 .proto 模式将 base64 proto 二进制文件转换为人类可读的 (json/xml)

rabbitmq - 解码 RabbitMQ 有效负载

serialization - 有没有类似 protoc 但跨平台编译器的东西

c++ - 用于向所有 mpi 进程发送和接收的时间高效设计模型 : MPI all 2 all communication

c++ - SetWindowsHook 同时支持 32 位和 64 位应用程序

c++ - 模板元编程以精确匹配函数签名

c++ - 具有数组构造函数方法的 constexpr 类

c++ - 新表达式的模板参数推导失败