Search code examples
c++lnk2019

can't solve this error c++ , although i have added the header file


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

Solution

  • 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.