Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you "decode" Visual Studio Link Errors?

Tags:

c++

linker

I'm not very experienced in C++, and when I have to work with another library and I get link errors, I'm completely in the dark on what the compiler is trying to tell me (other than it can't find something reference somewhere).

Are there any good links that describe, in detail, the meaning of the symbols and characters in a link error message? Or how to trouble shoot such errors?

For example, this is a link error I received recently:

testproj error LNK2019: unresolved external symbol "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) referenced in function "void __cdecl testproj::protobuf_BuildDesc_def_2eproto_AssignGlobalDescriptors(class google::protobuf::FileDescriptor const *)" (?protobuf_BuildDesc_def_2eproto_AssignGlobalDescriptors@testproj@@YAXPBVFileDescriptor@protobuf@google@@@Z)

like image 877
scottm Avatar asked Apr 08 '09 16:04

scottm


People also ask

How do you solve linking errors?

You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass . obj files or . lib files that contain the definitions to the linker.

What are link errors?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.


1 Answers

The symbols are the "mangled" versions of the function names. Basically because of c++ overloading (2 functions with different signatures can have the same name). The signature information is encoded into the name.

The message you pasted has both the encoded and plain text versions.

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)

are the same thing, just the later is mangled.

Notice that the mangled version starts with:

?0GeneratedMessageReflection@internal@protobuf@google

which corresponds nicely with:

google::protobuf::internal::GeneratedMessageReflection

Because the first few lines give you the relevant information, you can pretty much ignore the mangled versions. The plain text versions of the signatures are sufficient to fix the linker error.

like image 184
Evan Teran Avatar answered Sep 22 '22 10:09

Evan Teran