你如何"解码"Visual Studio链接错误?

sco*_*ttm 6 c++ linker

我在C++方面不是很有经验,当我必须使用另一个库并且我得到链接错误时,我完全不知道编译器试图告诉我什么(除了它找不到引用的东西)某处).

是否有任何良好的链接可以详细描述链接错误消息中符号和字符的含义?或者如何解决此类错误?

例如,这是我最近收到的链接错误:

testproj错误LNK2019:未解析的外部符号"public:__thiscall google :: protobuf :: internal :: GeneratedMessageReflection :: GeneratedMessageReflection(类google :: protobuf :: Descriptor const*,类google :: protobuf :: Message const*,int const*const,int,int,int,class google :: protobuf :: DescriptorPool const*,int)"(?? 0GeneratedMessageReflection @ internal @ protobuf @ google @@ QAE @ PBVDescriptor @ 23 @ PBVMessage @ 23 @ QBHHHHPBVDescriptorPool @ 23 @ H @ Z)在函数"void __cdecl testproj :: protobuf_BuildDesc_def_2eproto_AssignGlobalDescriptors(class google :: protobuf :: FileDescriptor const*)"中引用"(?protobuf_BuildDesc_def_2eproto_AssignGlobalDescriptors @ testproj @@ YAXPBVFileDescriptor @ protobuf @ google @@@ Z)

Eva*_*ran 5

符号是函数名称的"受损"版本.基本上是因为c ++重载(具有不同签名的2个函数可以具有相同的名称).签名信息被编码到名称中.

您粘贴的消息有两种编码的和纯文本版本.

public: __thiscall google::protobuf::internal::GeneratedMessageReflection::GeneratedMessageReflection(class google::protobuf::Descriptor const *,class google::protobuf::Message const *,int const * const,int,int,int,class google::protobuf::DescriptorPool const *,int)

?0GeneratedMessageReflection@internal@protobuf@google@@QAE@PBVDescriptor@23@PBVMessage@23@QBHHHHPBVDescriptorPool@23@H@Z)
Run Code Online (Sandbox Code Playgroud)

是同样的事情,只是后者被破坏了.

请注意,受损版本的开头是:

?0GeneratedMessageReflection@internal@protobuf@google
Run Code Online (Sandbox Code Playgroud)

与...很好地对应:

google::protobuf::internal::GeneratedMessageReflection
Run Code Online (Sandbox Code Playgroud)

因为前几行为您提供了相关信息,所以您几乎可以忽略这些错误的版本.签名的纯文本版本足以修复链接器错误.