Tutorial :How do you “decode” Visual Studio Link Errors?



Question:

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)


Solution:1

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.


Solution:2

Unresolved externals mean you are trying to call a function in another DLL, but you haven't linked to that DLL's LIB file.

It is usually pretty simple figuring out how to resolve these linker errors. The error message tells you exactly what you need to know:

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)"

This looks like you are trying to use a class named "GeneratedMessageReflection" in a google library. Find out what library provides this class and then go in to your compilers linker settings & add an "Additional Reference" to that library's LIB file.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »