Sei sulla pagina 1di 3

StackOverflowisaquestionandanswersiteforprofessionalandenthusiastprogrammers.

It's100%free,no
registrationrequired.

login

tour

signup

help

stackoverflowcareers

Takethe2minutetour

unresolvedexternalsymbol..noidea
duringmycodinginVisualStudioIgotanunresolvedexternalsymbolerrorandI'vegotnoideawhattodo...Idon'tknow,what'swrong...
Couldyoupleasedecipherme,whereshouldIbelookingforwhatkindoferrors?
1>Form.obj:errorLNK2019:unresolvedexternalsymbol"public:classField*__thiscall
Field::addField(classField*)"(?addField@Field@@QAEPAV1@PAV1@@Z)referencedinfunction
"public:void__thiscallForm::parse(classstd::basic_stringstream<char,struct
std::char_traits<char>,classstd::allocator<char>>&)"(?parse@Form@@QAEXAAV?
$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj:errorLNK2019:unresolvedexternalsymbol"public:virtualvoid__thiscall
Field::parse(classstd::basic_stringstream<char,structstd::char_traits<char>,class
std::allocator<char>>&)"(?parse@Field@@UAEXAAV?$basic_stringstream@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)referencedinfunction"public:__thiscall
InputField::InputField(classstd::basic_stringstream<char,struct
std::char_traits<char>,classstd::allocator<char>>&)"(??0InputField@@QAE@AAV?
$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Form.obj:errorLNK2001:unresolvedexternalsymbol"public:virtualvoid__thiscall
Field::prompt(void)"(?prompt@Field@@UAEXXZ)
1>Form.obj:errorLNK2001:unresolvedexternalsymbol"public:virtualclass
std::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>
__thiscallField::getName(void)"(?getName@Field@@UAE?AV?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj:errorLNK2001:unresolvedexternalsymbol"public:virtualclass
std::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>
__thiscallField::getType(void)"(?getType@Field@@UAE?AV?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>Form.obj:errorLNK2001:unresolvedexternalsymbol"public:virtualvoid__thiscall
Field::describe(void)"(?describe@Field@@UAEXXZ)
1>C:\Users\tomy\Documents\VisualStudio
2010\Projects\zapoctovkac++\Debug\zapoctovkac++.exe:fatalerrorLNK1120:6unresolved
externals
c++ unresolvedexternal

editedDec3'13at11:33

askedMar29'12at15:11

JohnSaunders
127k

16

145

Novellizator
294

900

10

31

11 Anunresolvedsymbolisonethatyou'vedeclaredsomewherebutneverdefined.Usually,itmeansyou've
#includedsomethirdpartylibrary'sheaderfilebutnottoldthelinkerwheretofindthecorresponding.obj
filesforthelibrary.deongMar29'12at15:16
1

Prettycommonmistakeisthatyoudefineafunctionasastandaloneandforgettheclassselectorinyour
.cppfile:Youdothis(wrong): voidmyFunc(){/*dostuff*/} Insteadofthis(right): void
A::myFunc(){/*dostuff*/} jave.web Mar11at18:43

7Answers

Thiserroroftenmeansthatsomefunctionhasadeclaration,butnotadefinition.
Example:
//A.hpp
classA
{
public:
voidmyFunc();//Functiondeclaration
};
//A.cpp
//Functiondefinition
voidA::myFunc()
{
//dostuff
}

Inyourcase,thedefinitioncannotbefound.Theissuecouldbethatyouareincludinga
headerfile,whichbringsinsomefunctiondeclarations,butyoueither:

1. donotdefinethefunctionsinyourcppfile(ifyouwrotethiscodeyourself)
2. donotincludethelib/dllfilethatcontainsthedefinitions
Acommonmistakeisthatyoudefineafunctionasastandaloneandforgettheclassselector,
e.g. A:: ,inyour.cppfile:
Wrong: voidmyFunc(){/*dostuff*/}
Right: voidA::myFunc(){/*dostuff*/}
editedMar12at23:44

answeredMar29'12at15:29

jave.web
1,413

ChrisMorris

11

29

1,617

18

8 +1forthedetailedbutsimpleexplanation.IzzaSep6'12at6:32
Howtoincludethesaidlibfileinmyproject?tMJ Aug29'14at13:11
@tMJItdependsonwhatenvironmentyouareusing.I'dlookuptutorialsonline,oronthissite.
ChrisMorris Aug30'14at14:27
@ChrisMorrisThefunction'sdefinitionwasn'tavailablenotbecauseIdidnotlinkitproperlyorsomething.
But,becausethedllwasnotinmemoryandhadtobeloadedviaaLoadLibrarycall.(FTR)tMJ Sep2'14
at10:08
Thelastadvicewasexactlytheproblemhere.Iwasdoing voidmyFunc(){} insteadof A::void
myFunc(){} . charlesrockbass Apr17at13:40

Checkyouareincludingallthesourcefileswithinyoursolutionthatyouarereferencing.
Ifyouarenotincludingthesourcefile(andthustheimplementation)fortheclass
projectitwon'tbebuiltandyouwillbeunabletolinkduringcompilation.

Field

inyour

Alternatively,perhapsyouareusingastaticordynamiclibraryandhaveforgottentotellthelinker
aboutthe .lib s?
editedMar29'12at15:40

answeredMar29'12at15:15
Konrad
9,604

15

48

102

Itlookstobemissingalibraryorinclude,youcantrytofigureoutwhatclassofyourlibrarythat
havegetName,getTypeect...andputthatintheheaderfileorusing#include.
Alsoifthesehappentobefromanexternallibrary,makesureyoureferencetothemonyour
projectfile.Forexampleiftheseclassbelongstoaabc.libtheninyourVisualStudio
ClickonProjectProperties.GotoConfigurationProperties,C/C++,Generate,verifyyoupointto
abc.liblocationunderAdditionalIncludeDirectories.UnderLinker,Input,makesureyouhavethe
abc.libunderAdditionalDependencies.
answeredMar29'12at15:20
Fylix
533

25

Ijusthadahardtimewiththis.Everythingwaslogicallysetup.Ideclaredaconstructorbut
didn'tdefineit
classSomeClass
{
SomeClass();//needstheSomeClass::SomeClass(){}functiondefinedsomewhere,even
here
}

IalmostbangedmyheadonmykeyboardwhenIforgotsomethingsoelementary.
answeredJan18at6:25
JoePlante
3,410

11

15

I'mdoingsomeC++forthefirsttimeinalongtime,andI'mgettingthiserrorwhenIforgettoadd
theClassName::prefixforthefunctiondefinition,sincethisisalittleuniquetoC++.Soremember
tocheckforthattoo!
answeredFeb23at21:13
MatthewHayes
28

POINTERS
Ihadthisproblemandsolveditbyusingpointer.Iseethatthiswasn'tyourissuebutIthoughtI'd
mentionitbecauseIsurewishithadbeenherewhenIsawthisanhourago.Myissuewasabout
declaringastaticmembervariablewithoutdefiningit(thedefinitionneededtocomeaftersome
othersetups)andofcourseapointerdoesn'tneedadefinition.Equallyelementarymistake:P
answeredMay7at9:09
Rabel
1

InadditiontotheexcellentanswerbyChrisMorrisabove,Ifoundaveryinterestingwayyoucan
receivethissamefaultifyouarecallingtoavirtualmethodthathasn'tbeensettopurebut
doesn'titsownimplementation.Itistheexactsamereason(thecompilercan'tfindan
implementationofthemethodandthereforecrooks),butmyIDEdidnotcatchthisfaultinthe
leastbit.
forexample,thefollowingcodewouldgetacompilationerrorwiththesameerrormessage:
//codetestinganinterface
classtest
{
voidmyFunc();
}
//defineaninterface
classIamInterface
{
virtualvoidmyFunc();
}
//implementationoftheinterface
classIamConcreteImpl
{
voidmyFunc()
{
1+1=2;
}
}

However,changingIamInterfacemyFunc()tobeapurevirtualmethod(amethodthat"must"be
implemented,thatthanavirtualmethodwhichisamethodthe"can"beoverridden)willeliminate
thecompilationerror.
//defineaninterface
classIamInterface
{
virtualvoidmyFunc()=0;
}

HopesthishelpsthenextStackOverFlowpersonsteppingthroughcode!
answeredMay11at13:26
GMLewisII
31

Potrebbero piacerti anche