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)
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.
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.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
this is the error i am getting
Error 13 error LNK2019: unresolved external symbol "public: bool
__thiscall ConfigInfo::GetDefaultTargetConfigSettings(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > const &,class CAdsTargetEditDlg &)" (?GetDefaultTargetConfigSettings#ConfigInfo##QAE_NABV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##AAVCAdsTargetEditDlg###Z) referenced in function "struct IADsUser * __cdecl __GetAdsUser(wchar_t const *,wchar_t const *)" (?__GetAdsUser##YAPAUIADsUser##PB_W0#Z) AdsUser.obj
Lets try to teach you to read the error you're getting.
The process of compilation in C++ is split into 2 parts: Compile your code (.cpp files) into object (.obj) files. This part is successful. Once that's done, the .obj files are handed off to what's called the linker, which is essentially responsible for taking all of the relevant components in the .obj files and hooking them all together in your .exe file. This is where the error is.
So lets take a look at the error you're getting:
Error 13 error LNK2019: unresolved external symbol "public: bool
__thiscall ConfigInfo::GetDefaultTargetConfigSettings(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > const &,class CAdsTargetEditDlg &)" (?GetDefaultTargetConfigSettings#ConfigInfo##QAE_NABV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##AAVCAdsTargetEditDlg###Z) referenced in function "struct IADsUser * __cdecl __GetAdsUser(wchar_t const *,wchar_t const *)" (?__GetAdsUser##YAPAUIADsUser##PB_W0#Z) AdsUser.obj
The first part Error 13 error LNK2019: unresolved external symbol says that the linker was looking for something, but wasn't able to find it in any of the object files.
The first quoted string public: bool
__thiscall ConfigInfo::GetDefaultTargetConfigSettings(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > const &,class CAdsTargetEditDlg &) is the signature or declaration of what (a function) it's looking for, but can't find.
The part that follows the string in parenthesis is essentially an alternate form of the same thing, I suspect some people are really familiar with that format... but it's really of no use to most people.
After the parenthesis it says referenced in function followed by another quoted string struct IADsUser * __cdecl __GetAdsUser(wchar_t const *,wchar_t const *). The second quoted string is the signature of the function that is calling the missing one.
So, all together this error says 'Hey, function "IADsUser* GetAdsUser(wchar_t const *,wchar_t const *)" is looking for a function "bool
ConfigInfo::GetDefaultTargetConfigSettings(class ATL::CStringT > > const &,class CAdsTargetEditDlg &)" but I can't find it.'
Because it made it to the linker stage, we know the function declaration is included in the header file(functions won't compile if they can't find a valid declaration)... but it's not in any of the object files. That means it was declared, but never defined. You've either got a call somewhere in GetAdsUser to ConfigInfo::GetDefaultTargetConfigSettings that is bad or you're missing the definition/body of the function somewhere.
Learning to read the errors you're getting in extremely important.
We have code that uses the ICU library for working with Unicode strings. When we try to build it, we get no compile errors, but the link fails. I created a small test program with the following code:
#define U_STATIC_IMPLEMENTATION
#undef INT64_C
#undef UINT64_C
#include <unicode/coll.h>
void icu_test()
{
UErrorCode success = U_ZERO_ERROR;
Collator* myCollator = Collator::createInstance(success);
VERIFY(U_SUCCESS(success));
myCollator->setStrength(Collator::QUATERNARY);
UChar Word1[10] = _T("this");
UChar Word2[10] = _T("that");
// Compare two strings in the default locale
bool result = myCollator->greater(Word1, Word2);
}
This program also fails to link with:
error LNK2019: unresolved external symbol "public: __thiscall
icu_3_2::UnicodeString::UnicodeString(wchar_t const *)"
(??0UnicodeString#icu_3_2##QAE#PB_W#Z) referenced in function "void
__cdecl icu_test(void)" (?icu_test##YAXXZ)
(Is 0UnicodeString the constructor, perhaps?) When I use dumpbin to look at the exported symbols in the ICU libraries, I see the following:
??0UnicodeString#icu_3_2##QAE#ABV01##Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(class icu_3_2::UnicodeString const &))
??0UnicodeString#icu_3_2##QAE#ABV01#H#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(class icu_3_2::UnicodeString const &,int))
??0UnicodeString#icu_3_2##QAE#ABV01#HH#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(class icu_3_2::UnicodeString const &,int,int))
??0UnicodeString#icu_3_2##QAE#CPBGH#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(signed char,unsigned short const *,int))
??0UnicodeString#icu_3_2##QAE#G#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(unsigned short))
??0UnicodeString#icu_3_2##QAE#H#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(int))
??0UnicodeString#icu_3_2##QAE#HHH#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(int,int,int))
??0UnicodeString#icu_3_2##QAE#PAGHH#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(unsigned short *,int,int))
??0UnicodeString#icu_3_2##QAE#PBD0#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(char const *,char const *))
??0UnicodeString#icu_3_2##QAE#PBDH0#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(char const *,int,char const *))
??0UnicodeString#icu_3_2##QAE#PBDHPAUUConverter##AAW4UErrorCode###Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(char const *,int,struct UConverter *,enum UErrorCode &))
??0UnicodeString#icu_3_2##QAE#PBDHW4EInvariant#01##Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(char const *,int,enum icu_3_2::UnicodeString::EInvariant))
??0UnicodeString#icu_3_2##QAE#PBG#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(unsigned short const *))
??0UnicodeString#icu_3_2##QAE#PBGH#Z (public: __thiscall icu_3_2::UnicodeString::UnicodeString(unsigned short const *,int))
??0UnicodeString#icu_3_2##QAE#XZ (public: __thiscall icu_3_2::UnicodeString::UnicodeString(void))
So none of these quite match the first unresolved external, because of the stuff at the end of the identifier (e.g. ##QAE#PB_W#Z), which does not come from our code. Not sure how this is generated or what to do about it.
I tried downloading the latest version of ICU (60.2), but it only comes in a x64 version, while our program builds for x86.
I made sure that the ICU library folder is included in the link settings.
We also made sure to define U_STATIC_IMPLEMENTATION, as described in this post:
Why do I get link errors when the symbol is clearly present in the static library I link against?
In that post, they were able to locate the relevant symbol in the library, but we cannot.
Can anyone help us understand what is causing this link error?
I tried building a static library of ICU 60.2 but ran into problems and I was unable to get help from ICU support to build it.
I tried downloading pre-built ICU 59.1 libraries from this website. But had a different linker error and no idea what to do with that.
I saw that my code was trying to pass a wchar_t* to icu::greater(), which expects UnicodeString arguments, so I inferred that this is where type conversion causes the UnicodeString to be constructed. I changed the code to do an explicit conversion to UnicodeString and then pass that, but I still got the same linker error.
Finally, my coworker found some information about a potential problem with wchar_t. So that was it - our best understanding is that since our code was originally working with MS Visual C++ 6.0, and it was able to link to ICU 3.2 in that context, it was linking with the old definition of wchar_t, but the new definition of wchar_t was changing the way the name decoration was being generated. Adding -Zc:wchar_t- to the compile options (in VS 2017, go to Project Properties, C/C++ All Options, 'Additional Options' line), caused it to link successfully after a full recompile.
Very subtle.
Disclaimer: there is a high chance this is very specific to Unreal Engine, but I haven't got an answer there so I thought I'd try a more general query here. Sorry if this is considered off topic/too specific
I am getting a link error compiling the following code in Unreal Engine 4:
RHISetRenderTarget(TextureRenderTarget->GetRenderTargetTexture(), NULL);
This is being called within a macro (ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER) but the link error happens even if you don't.
The error itself is:
MaterialToTextureRenderer.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl RHISetRenderTargets(unsigned int,class FRHIRenderTargetView const *,class FRHITexture *,unsigned int,class FRHIUnorderedAccessView * const *)" (__imp_?RHISetRenderTargets##YAXIPEBVFRHIRenderTargetView##PEAVFRHITexture##IPEBQEAVFRHIUnorderedAccessView###Z) referenced in function "void __cdecl RHISetRenderTarget(class FRHITexture *,class FRHITexture *)" (?RHISetRenderTarget##YAXPEAVFRHITexture##0#Z)
Compressed for readability:
unresolved external symbol: void RHISetRenderTargets(unsigned int, FRHIRenderTargetView const *,FRHITexture *,unsigned int,FRHIUnorderedAccessView * const *)
referenced in: void RHISetRenderTarget(FRHITexture *,FRHITexture *)
(The method the unlinked method is referenced in is the method I am calling).
And 4 other simillar link errors.
I'm not by any stretch of the imagination a C++ expert, but my understanding is a link error is caused when the header file is correctly included but then it can't actual find an implementation of the method to point to.
What I don't understand is, the method whose implementation it can't find, is within the Unreal Engine (which I am assuming doesn't actually have missing method implementations etc!).
Further, both the method I am calling, and the method it is calling (and can't link) are both defined inline in the same header file. The only thing I can see that could be wrong is the method that is being used is declared and implemented further down the header file, but I don't believe that could be a problem (certainly not a link problem).
Be sure that you include RHI and RenderCore in your .build.cs for your target like this
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RHI", "RenderCore", "ShaderCore" });
I have a third party libs. (msvc10) a MT/MD (Static cfgs's) and dynamic DLL cfg.
I have qt + msvc10 express + win sdk.7
Ok , I use the existing examples offered, (using the libs) I can't compile ..... I have 4 unresolved external errors of the same lib.
(But I have zero errors for the others)
I have not support for these lib...... (but they are legal, I am a member without rights)
Which are the steps to investigate a possible fix? Where I have to look ?
Thanks.
Edit 1:
The errors was:
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueW#32 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey#4 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegQueryValueExW#24 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExW#20 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
..\exe\OdaQtApp.exe : fatal error LNK1120: 13 unresolved externals
During this post I have received a solution: I have to link with Advapi32.lib...
My question is : how can I know this ?
I have tried the dependencyywalker, but it cant use the .lib's....
During this post I have received a solution: I have to link with Advapi32.lib... My question is : how can I know this?
When you get an "unresolved external" error from the linker, that means that it was looking for a match for a function or variable name that some object file needs and the linker was unable to find that name defined in one of the object files or libraries.
Start by looking at the first of these errors (I've reformatted it a bit to make it slightly more readable - I encourage yo to do the same next time you come across one of these):
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol
__imp__RegEnumValueW#32 referenced in function
"public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(
class OdTtfDescriptor const &,class OdString &)"
(?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
There's a lot of stuff in that error message (much of it may look like garbage). Fortunately, much of it can be ignored in most cases. The most important item is that the linker is looking for the symbol __imp__RegEnumValueW#32 The name has some gunk on it, but fortunately it's pretty recognizable anyway.
the __imp__ prefix indicates it's looking for a DLL import. In nearly all cases that can be ignored for your purposes.
the #32 suffix is something the Microsoft compiler adds to function names for certain calling conventions. It's also generally not important for your purposes (for the record it indicates that the function expects 32 bytes of argument data)
So we're left with the fact that the linker is looking for RegEnumValueW. That looks a lot like the name of a Win32 API.
If you look at the docs for RegEnumValueW (or RegEnumValue, since many Win32 APIs have both an A and a W variant to handle ANSI/UNICODE builds) we'll find in the documentation this bit of information:
Requirements
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Winreg.h (include Windows.h)
>> Library Advapi32.lib
DLL Advapi32.dll
Unicode and ANSI names RegEnumValueW (Unicode) and
RegEnumValueA (ANSI)
That's how you know you need advapi32.lib.
So in the future, when you get an "unresolved external" error from the linker, just ignore most of the gunk in the error message and concentrate on the symbol it says it can't find - that should lead you to the library, object file or other item you might be missing.
Just for the record, advapi32.lib will be needed by most Windows applications of any complexity.
you can try to use dependencywalker to see the list of dependencies for your dlls and see what it's missing.
have you entered the *.lib file in the linker options? (input --> additional dependencies"), and in addition the path to the .lib in libraries directories option?
HI I'm an internship student and my job is porting a program from linux c to visual c.
I've to use Berkeley DB and Visual C++.
after trying for a while, i get the linking error
berkeleyDB.obj : error LNK2019: unresolved external symbol "int __cdecl database_select_end(unsigned int,unsigned int,struct chunk * const,int)" (?database_select_end##YAHIIQAUchunk##H#Z) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk##YAXIPAIH#Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "void __cdecl database_sync(void)" (?database_sync##YAXXZ) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk##YAXIPAIH#Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "void __cdecl database_insert_bluk(struct chunk *,int)" (?database_insert_bluk##YAXPAUchunk##H#Z) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk##YAXIPAIH#Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "int __cdecl database_open(int,char *)" (?database_open##YAHHPAD#Z) referenced in function _main
no idea what are those,
pls help me
They're C++-mangled (or 'decorated') function names. C++ allows function overloading - multiple functions with the same name but with different parameter signatures - and so it needs to encode the parameters etc. into the function name to differentiate the multiple overloads at link time. Most likely your DB library was built as C and won't have decorated names.
Try wrapping your db.h include in an extern "C"
extern "C"
{
#include <db/db.h>
}
to tell the compiler to treat the API as C functions, not C++.
(It looks like you've got a typo in there too: database_insert_bluk not _bulk.)
Alternatively, it looks like Berkeley DB ship a C++ interface #include <db/db_cxx.h> you could use instead, although if you're porting code it may be easier to stick to the C interface. The difference is probably that the Linux code you're porting was compiled as C whereas here you're compiling it as C++.
From the other comment you've posted: if your problem is that you're actually not linking in Berkeley DB at all then you'll need to go into project settings (right-click on the project name), the C++ link tab, and then add the .lib file to the list of libraries to link into your project. You may need to specify the path to find this too, and you should do this for both debug and release modes (the drop down at the top of the settings).