Linking static library including template

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roland Raschke

    Linking static library including template

    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<uns igned 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<uns igned 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
  • Kevin Goodsell

    #2
    Re: Linking static library including template

    Roland Raschke wrote:
    [color=blue]
    > Hi,
    > I'm a novice in using templates and want to write a static library
    > with some communication classes.[/color]

    "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.
    [color=blue]
    > 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<uns igned char>::PutData( unsigned char const &)"[/color]

    [34.14] How can I avoid linker errors with my template classes?


    While you're at it:

    [5.8] How do I post a question about code that doesn't work correctly?


    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.

    Comment

    Working...