Linking static library including template

Discussion in 'C++' started by Roland Raschke, Sep 22, 2003.

  1. Hi,
    I'm a novice in using templates and want to write a static library
    with some communication classes. One of these classes uses two
    instances of a ringbuffer template as class members:

    template <class T> class CRingBuffer
    {
    public:
    ...
    bool PutData( const T& value );
    ...
    };

    typedef CRingBuffer<unsigned char> tByteFIFO;
    class CCommDriver
    {
    ...
    tByteFIFO m_RxRing;
    ...
    };

    I can compile and link this library without errors, but if want to use
    the class CCommDriver in an application the linker returns errors for
    any used member function of CRingBuffer, i.e.:
    error LNK2001: Unresolved external "public: bool __thiscall
    CRingBuffer<unsigned char>::putData(unsigned char const &)"
    What's the problem? I think the compiler should create the necessary
    template code for unsigned byte because it is used inside the
    CCommDriver class...

    Thanks for your help!

    Regards,
    Roland
     
    Roland Raschke, Sep 22, 2003
    #1
    1. Advertising

  2. Roland Raschke wrote:

    > Hi,
    > I'm a novice in using templates and want to write a static library
    > with some communication classes.


    "Static library" is not something that is defined as part of C++. If
    you're having a problem with that, the appropriate place to ask is a
    group that discusses your implementation. comp.lang.c++ only discusses
    the C++ language itself.

    > I can compile and link this library without errors, but if want to use
    > the class CCommDriver in an application the linker returns errors for
    > any used member function of CRingBuffer, i.e.:
    > error LNK2001: Unresolved external "public: bool __thiscall
    > CRingBuffer<unsigned char>::putData(unsigned char const &)"


    [34.14] How can I avoid linker errors with my template classes?
    http://www.parashift.com/c -faq-lite/containers-and-templates.html#faq-34.14

    While you're at it:

    [5.8] How do I post a question about code that doesn't work correctly?
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Sep 22, 2003
    #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. Anthony Yio

    Linking to Static library of C

    Anthony Yio, May 20, 2004, in forum: C++
    Replies:
    1
    Views:
    356
    John Harrison
    May 20, 2004
  2. Gernot Frisch

    linking static template variable

    Gernot Frisch, Jan 2, 2008, in forum: C++
    Replies:
    5
    Views:
    373
    James Kanze
    Jan 2, 2008
  3. Jaco Naude
    Replies:
    1
    Views:
    418
    James Kanze
    Jul 25, 2008
  4. F van der Meeren

    Linking to a Python static library.

    F van der Meeren, Jun 15, 2010, in forum: Python
    Replies:
    0
    Views:
    225
    F van der Meeren
    Jun 15, 2010
  5. Avi
    Replies:
    0
    Views:
    187
Loading...

Share This Page