LNK2019: unresolved external symbol

what are the reasons that I can get this error?
//error message

1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: __thiscall cServer<unsigned short,class cUser4Login>::cServer<unsigned short,class cUser4Login>(class cUser4Login &)" (??0?$cServer@GVcUser4Login@@@@QAE@AAVcUser4Login@@@Z) referenced in function "public: __thiscall cLoginServer::cLoginServer(void)" (??0cLoginServer@@QAE@XZ)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: __thiscall cServer<unsigned short,unsigned short>::cServer<unsigned short,unsigned short>(void)" (??0?$cServer@GG@@QAE@XZ) referenced in function "public: __thiscall cLoginServer::cLoginServer(void)" (??0cLoginServer@@QAE@XZ)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: void __thiscall cServer<unsigned short,class cUser4Login>::grow_to(unsigned int)" (?grow_to@?$cServer@GVcUser4Login@@@@QAEXI@Z) referenced in function "public: void __thiscall cLoginServer::LoadConfigFile(void)" (?LoadConfigFile@cLoginServer@@QAEXXZ)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: unsigned int __thiscall cServer<unsigned short,class cUser4Login>::capacity(void)" (?capacity@?$cServer@GVcUser4Login@@@@QAEIXZ) referenced in function "public: void __thiscall cLoginServer::SaveConfigFile(void)" (?SaveConfigFile@cLoginServer@@QAEXXZ)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: unsigned int __thiscall cServer<unsigned short,unsigned short>::capacity(void)" (?capacity@?$cServer@GG@@QAEIXZ) referenced in function "public: void __thiscall cLoginServer::ShutDown(unsigned char)" (?ShutDown@cLoginServer@@QAEXE@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: void __thiscall cServer<unsigned short,class cUser4Login>::remove(unsigned short)" (?remove@?$cServer@GVcUser4Login@@@@QAEXG@Z) referenced in function "public: void __thiscall cLoginServer::LogOut(unsigned short)" (?LogOut@cLoginServer@@QAEXG@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: void __thiscall cServer<unsigned short,unsigned short>::remove(unsigned short)" (?remove@?$cServer@GG@@QAEXG@Z) referenced in function "public: void __thiscall cLoginServer::LogOutOf(unsigned short)" (?LogOutOf@cLoginServer@@QAEXG@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: unsigned short __thiscall cServer<unsigned short,unsigned short>::insert(unsigned short)" (?insert@?$cServer@GG@@QAEGG@Z) referenced in function "public: bool __thiscall cLoginServer::LogInTo(unsigned short,unsigned char)" (?LogInTo@cLoginServer@@QAE_NGE@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: unsigned short & __thiscall cServer<unsigned short,unsigned short>::operator[](unsigned short const &)" (??A?$cServer@GG@@QAEAAGABG@Z) referenced in function "public: bool __thiscall cLoginServer::Kick(unsigned char,unsigned short,unsigned char)" (?Kick@cLoginServer@@QAE_NEGE@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: void __thiscall cServer<unsigned short,unsigned short>::grow_to(unsigned int)" (?grow_to@?$cServer@GG@@QAEXI@Z) referenced in function "public: bool __thiscall cLoginServer::CreateServer(unsigned int,unsigned int,unsigned char,char *,unsigned int,unsigned char)" (?CreateServer@cLoginServer@@QAE_NIIEPADIE@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: void __thiscall cServer<unsigned short,unsigned short>::clear(void)" (?clear@?$cServer@GG@@QAEXXZ) referenced in function "public: bool __thiscall cLoginServer::CreateServer(unsigned int,unsigned int,unsigned char,char *,unsigned int,unsigned char)" (?CreateServer@cLoginServer@@QAE_NIIEPADIE@Z)
1>cLoginServer.obj : error LNK2019: unresolved external symbol "public: unsigned short __thiscall cServer<unsigned short,class cUser4Login>::insert(class cInfo &)" (?insert@?$cServer@GVcUser4Login@@@@QAEGAAVcInfo@@@Z) referenced in function "public: bool __thiscall cLoginServer::ProcessPacket(class cDataPacket *)" (?ProcessPacket@cLoginServer@@QAE_NPAVcDataPacket@@@Z)


those function calls that the compiler cannot find are my own, not a library's.
the declarations of the functions are in a header file and the definitions are in .cpp file. I would post the code, but it would go beyond the length allowed. I just need to know some things to check. I have been looking around the forums and found that most people have problems with linking librarys, but this is not a library linking problem.
1. cLoginServer.cpp should include the header file where the declarations are.
2. The header file should declare the functions with the "extern" keyword.
the loginserver.cpp does include the header where the functions are declared.
the functions are declared inside of a class inside the header file named cServer.h


the functions are declared inside of a class cServer

and I declare all the functions inside the class header file then the definitions are inside of their own .cpp file


any other reasons for the unresolved external symbol error?

all header files are guarded with an #ifndef
Last edited on
I found the class that is causing the errors, its short enough that I can post the code take a look at this
... why would this error be caused?

1>mathtest.obj : error LNK2019: unresolved external symbol "public: __thiscall cId<int,int>::cId<int,int>(int,int)" (??0?$cId@HH@@QAE@HH@Z) referenced in function _wmain



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// main cpp
#include "stdafx.h"
#include <iostream>
#include "tester.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int o=9l;
	cId<int, int> k(300, o);
	return 0;
}

// tester.h
#ifndef CTESTER_H
#define CTESTER_H

template<class T, class O>class cId{
public:
	cId(T grow, O dum);
	
};

#endif

// tester.cpp

#include "stdafx.h"
#include "tester.h"

template<class T, class O>cId<T,O>::cId(T grow, O dum){ }




I found out that I cannot create any templates. All template cause a linker error.. uhmm i found my problem.... any suggestions?
Last edited on
sigh.. took me 6 hours to find out that you cannot have a companion .cpp file when creating templates


all declarations and defintitions must be in the header file...... sigh


what a waste of time..
That is not true - you can have a companion cpp file.
If in your original tester.cpp file you had done this:
1
2
3
4
5
6
7
8
// tester.cpp

#include "stdafx.h"
#include "tester.h"

template<class T, class O>cId<T,O>::cId(T grow, O dum){ }

template class cId<int,int>; //explicit instantiation 


and compiled it as normal, it would have worked.
Yeah, except that then main.cpp would have no idea what cId<T,O>::cId() does.
He has included tester.h in main.cpp anyway.
If the compiler cannot find a template function - it puts a marker sameway as it does for any normal missing function definition and let the linker sort it out.

If he compiles the tester.cpp file (the way I have shown) then the explicit instantiation of
the cId class will cretae the functions for all the instatiable functions in the class and
there will be no linker problems.

Like I said, it is called explicit instatiation.

Trust me on this.
Topic archived. No new replies allowed.