Compiling error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seforo
    New Member
    • Nov 2006
    • 60

    Compiling error

    Hi guys,
    I have a class declared and defined in AliHLTMessageQu eue.h and AliHLTMessageQu eue.cxx respectively

    template<typena me MessageType, int kSignalNumber = SIGUSR1>
    class AliHLTMessageQu eue{.//declarations etc..}

    I also have a file queueTest.cxx where i call AliHLTMessageQu eue methods.
    I declare my object like as:
    AliHLTMessageQu eue<int> queue(20000000) ;
    And I made this call somewhere in queueTest.cxx:
    queue.Push(m, COUNT,true,0,tr ue);

    I compile my files with Makefile and this is the line in the make file:
    g++ -O3 -Wall -Werror -DNDEBUG -pthread $(CXXFlags) AliHLTMessageQu eue.cxx queueTest.cxx -o $@

    I get the error:
    undefined reference to`AliHLTMessag eQueue<int, 10>::Push(int const*, unsigned, int, bool, float, bool)'

    I DON'T UNDERSTAND THIS BECAUSE I INCLUDE THE SOURCE FILE WHERE I DEFINED THE METHOD Push WHILE COMPILING. Any suggestions?
    Last edited by seforo; Nov 20 '07, 01:30 PM. Reason: I left important information
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You are using templates.

    Templates are neither declararions or definitions. They are more like macros. That is, they are a pattern the compiler uses. When you create a variable from a template, the compiler makes a copy of the template and replaces the placeholder typename with your type used to create the varaible.

    That means you do not include a source file butyou do include the template. In this case the template would be the class declaration plus all of the class methods. These should be in a header file and you should include this header in all source files that use the template.

    Comment

    Working...