tags:

views:

830

answers:

2

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)

+2  A: 

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.

John Dibling
I've done that (added the directory of the .lib file to "Additional Library Directories"), could that mean there is a problem with the library? Or, is there another way to reference the library that I don't know of?
scottm
+3  A: 

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.

Evan Teran
I see. Is there a setting in visual studio to hide the mangled version?
scottm
what version of visual studio are you using?
Evan Teran
I switch between 2003 and 2008
scottm
Not sure if there is a way to suppress the mangled versions. But they are fairly easy to filter out. Just read it carefully and ignore the all the entries with @'s and ?'s.
Evan Teran
All your error is really saying is "can't find the function 'GeneratedMessageReflection' which is used in a function called 'protobuf_BuildDesc_def_2eproto_AssignGlobalDescriptors'"
Evan Teran
perhaps there is an additional library you need to link to in order to use Google's protocol buffers?
Evan Teran
I'm not sure, the source only contains one library, so I assume that's all I need. I've posted in the discussion group on google code to solve this particular problem.
scottm