Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unresolved external symbol due to name mangling

I am facing linker error for a XERCES function while upgrading it from 2.6 to 2.8

unresolved external symbol (?resolveEntity@HandlerBase@xercesc_2_8@@UAEPAVInputSource@2@QBG0@Z)

I checked the xerces-c_2.8.lib and found that name lib is bit different that the one in my .obj file It is as shown

?resolveEntity@HandlerBase@xercesc_2_8@@UAEPAVInputSource@2@QB_W0@Z

So I understand that linker wont find the match and throw error.

But I am unable to understand why my .obj file contains different signature.

code is including correct header files and lib from still incorrect name.

Any help would be appreciated.

like image 534
NoName Avatar asked Sep 28 '12 12:09

NoName


People also ask

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What causes unresolved external symbol?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.

How do I fix LNK1120?

Error LNK1120 reports the number of unresolved external symbol errors in the current link. Each unresolved external symbol first gets reported by a LNK2001 or LNK2019 error. The LNK1120 message comes last, and shows the unresolved symbol error count. You don't need to fix this error.

What kind of error is unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. It's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.


1 Answers

You can use the undname.exe utility to recover the original C++ declaration.

?resolveEntity@HandlerBase@xercesc_2_8@@UAEPAVInputSource@2@QBG0@Z converts to:

virtual class xercesc_2_8::InputSource * 
__thiscall xercesc_2_8::HandlerBase::resolveEntity(
    unsigned short const * const,
    unsigned short const * const)

?resolveEntity@HandlerBase@xercesc_2_8@@UAEPAVInputSource@2@QB_W0@Z converts to:

virtual class xercesc_2_8::InputSource * 
__thiscall xercesc_2_8::HandlerBase::resolveEntity(
     wchar_t const * const,
     wchar_t const * const)

Note the differences in the argument types, unsigned short vs wchar_t. For some reason, your compiler is not recognizing the wchar_t type. That could be because you have a very old compiler. Or it can be an option set wrong, on msvc it is C/C++, Language, "Treat wchar_t as Built-in type". Or you've got a macro that hacks the string type to unsigned short.

like image 154
Hans Passant Avatar answered Sep 28 '22 09:09

Hans Passant