LNK2019 - Unresolved external symbol

Discussion in 'C++' started by repairman2003@gmail.com, Aug 28, 2008.

  1. Guest

    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?
     
    , Aug 28, 2008
    #1
    1. Advertising

  2. Guest

    On Aug 27, 10:31 pm, Paul Pluzhnikov <>
    wrote:
    > "" <> 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?
     
    , Aug 28, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen
    Replies:
    8
    Views:
    11,020
    Scott Allen
    May 2, 2004
  2. Mastadex
    Replies:
    4
    Views:
    760
    Mastadex
    Oct 1, 2005
  3. NewsGroup
    Replies:
    3
    Views:
    685
    Michael
    Oct 27, 2006
  4. Trent
    Replies:
    9
    Views:
    646
    Trent
    Jun 29, 2007
  5. Tauqir
    Replies:
    2
    Views:
    2,274
    Tauqir
    Apr 9, 2010
Loading...

Share This Page