Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > LNK2019 - Unresolved external symbol

Reply
Thread Tools

LNK2019 - Unresolved external symbol

 
 
repairman2003@gmail.com
Guest
Posts: n/a
 
      08-28-2008
Here's where the linker is running into an issue:

template <typename T>
void Engine::setEventReceiver(T receiver)
{
m_device->setEventReceiver(receiver);
}

I've got that function in a static library that my client program is
calling. I'm almost certain that this linker error is being caused
because the lib has no information about the type of object I'm
sending it. The type I'm passing into this is a custom type that
should not be in the lib file--it's a class that is holds client side
events and doesn't belong in this library.

here is the class info I'm using for the type:

class EventReceiver : public IEventReceiver
{
...
};

and the calling info in main:

Engine* engine...
EventReceiver receiver;

engine->setEventReceiver<EventReceive>(receiver);

Am I correct in why it is throwing that linker issue? What are my
options in getting around this?
 
Reply With Quote
 
 
 
 
repairman2003@gmail.com
Guest
Posts: n/a
 
      08-28-2008
On Aug 27, 10:31*pm, Paul Pluzhnikov <(E-Mail Removed)>
wrote:
> "(E-Mail Removed)" <(E-Mail Removed)> writes:
> > template <typename T>
> > void Engine::setEventReceiver(T receiver)
> > {
> > * *m_device->setEventReceiver(receiver);
> > }

>
> > I've got that function in a static library that my client program is
> > calling.

>
> No, you didn't. You may have some instantiations of that template
> function, but you certainly don't have the template itself in a
> static library.
>
> > I'm almost certain that this linker error is being caused
> > because the lib has no information about the type of object I'm
> > sending it. The type I'm passing into this is a custom type that
> > should not be in the lib file--it's a class that is holds client side
> > events and doesn't belong in this library.

>
> You appear to have fundamental misunderstanding of how templates work.
>
> > and the calling info in main:

>
> > Engine* engine...
> > EventReceiver receiver;

>
> > engine->setEventReceiver<EventReceive>(receiver);

>
> The *body* of setEventReceiver() must be available here (e.g. from
> an included header file). If (as I suspect) it isn't, then linker
> error is entirely expected.
>
> > Am I correct in why it is throwing that linker issue? *What are my
> > options in getting around this?

>
> Put the body of template function into a header file, so it can be
> instantiated when the type if 'T' is known.
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.


Thanks for you quick response. It links correctly now. I had the
body of the template function in a .cpp file instead of in its .h
file. So you cannot have a template function definition in a header
file and its implementation in a separate file?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error LNK2019: unresolved external symbol _main referenced infunction ___tmainCRTStartup MSVCRTD.lib Win32App Tauqir C++ 2 04-09-2010 08:32 AM
What is Error 1 error LNK2019: unresolved external symbol ???? Trent C++ 9 06-29-2007 08:32 PM
error LNK2019: unresolved external symbol - cl compiler NewsGroup C++ 3 10-27-2006 05:50 PM
"LNK2019 - Unresolved external Symbol" while using templates Mastadex C++ 4 09-30-2005 11:20 PM
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM



Advertisments