Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

Linker Error: Unresolved External Symbol

Started by PunaProgrammer chris Jun 17, 2006 at 5:32 AM 3 replies 1k views
Original Post
PunaProgrammer chris
PunaProgrammer chris
I get a linker error when I try to compile my program. Here is the revelant code:

From Network.h:
class Client
{
public:
	template <class Class> void SendPacket(Class object, unsigned char packetID, int packetStream);
        //other stuff removed due to irrelevancy...
};

From Client.cpp:
template <class Class>
void Client::SendPacket(Class object, unsigned char packetID, int packetStream)
{
	IdentifiedPacket <Class> data(packetID, object);
	client->Send((char*) data, sizeof(TemplatedClass<Classy>), HIGH_PRIORITY, RELIABLE_ORDERED, packetStream);
}

From main.cpp:
if(input.CheckKey(SDLK_a, SDL_KEYDOWN))
{
	cli->SendPacket(true, TEXT_STATE, 1);
}
else if(input.CheckKey(SDLK_a, SDL_KEYUP))
{
	cli->SendPacket(false, TEXT_STATE, 1);
}

Error I get:
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Client::SendPacket<bool>(bool,unsigned char,int)" (??$SendPacket@_N@Client@@QAEX_NEH@Z) referenced in function "void __cdecl InputCheck(void)" (?InputCheck@@YAXXZ)


I am including Network.h into both files. This is the only error I get. Any help would be greatly appreciated. Thanks.
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by PunaProgrammer chris
I get a linker error when I try to compile my program. Here is the revelant code:

*** Source Snippet Removed ***

I am including Network.h into both files. This is the only error I get. Any help would be greatly appreciated. Thanks.


Hello,

I only see the declaration of the function. Where is its definition? It should also be in the header file.

HTH,
PunaProgrammer chris
PunaProgrammer chris
Umm... the definition is right in the Client.cpp. And I shouldn't put it in the header file, because it is being included into multiple cpp files.
Edit: Assuming by "the function", you are refering(sp?) to SendPacket.
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by PunaProgrammer chris
Umm... the definition is right in the Client.cpp. And I shouldn't put it in the header file, because it is being included into multiple cpp files.


It's a template function - you have no choice but to put it in your header file :) Don't worry. Because of its template nature, the compiler will not instantiate it when he'll find the definition - he is going to instantiate it when he finds the uses. You don't have to fear the multiple redefinition problem in this particular case.

HTH,
PunaProgrammer chris
PunaProgrammer chris
I tried that before, but apparently after I moved it to the header, I needed to do a clean build. Heh. Thanks for the template help.

Edit: new compile error though now... new thread!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.