title: C++ failed linkage, undefined reference
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file">Why can templates only be implemented in the header file?</a><br>
    <a href="https://stackoverflow.com/questions/614233/undefined-reference-to-function-template-when-used-with-string-gcc">Undefined reference to function template when used with string (GCC)</a><br>
    <a href="https://stackoverflow.com/q/648900/">C++ templates, undefined reference</a>  </p>
  </blockquote>
  
  
  
  <p>I feel I'm missing something linking a C++ project.
  I'm not sure if the problem is in the header sources or includes so I made a minimal code sample to demonstrate it.</p>
  
  <p>Main module 
  minmain.cpp:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;vector&gt;
   #include &lt;string&gt;
   #include "nodemin.h"
  
   using namespace std;
  
   int main()
   {
       // Blist libs are included
       Node&lt;int&gt;* ndNew = ndNew-&gt;Root(2);
  
       return 0;
   }
  </code></pre>
  
  <p>Header file 
  nodemin.h:</p>
  
  <pre><code> #ifndef NODETEMP_H_
   #define NODETEMP_H_
  
   using namespace std;
  
   template&lt;class T&gt;
   class Node
   {
   protected:
  
      Node* m_ndFather;
      vector&lt;Node*&gt; m_vecSons;
      T m_Content;
  
      Node(Node* ndFather, T Content);
  
   public:
  
       // Creates a node to serve as a root
           static  Node&lt;T&gt;* Root(T RootTitle);
   };
  
   #endif
  </code></pre>
  
  <p>node module 
  nodemin.cpp:</p>
  
  <pre><code> #include &lt;iostream&gt;
   #include &lt;string.h&gt;
   #include &lt;vector&gt;
   #include "nodemin.h"
  
   using namespace std;
  
   template &lt;class T&gt;
   Node&lt;T&gt;::Node(Node* ndFather, T Content)
   {
      this-&gt;m_ndFather = ndFather;
      this-&gt;m_Content = Content;
   }
  
   template &lt;class T&gt;
   Node&lt;T&gt;* Node&lt;T&gt;::Root(T RootTitle) { return(new Node(0, RootTitle)); }
  </code></pre>
  
  <p>Compile line:</p>
  
  <pre><code> #g++ -Wall -g mainmin.cpp nodemin.cpp
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> /tmp/ccMI0eNd.o: In function `main':
   /home/******/projects/.../src/Node/mainmin.cpp:11: undefined reference to`Node&lt;int&gt;::Root(int)'
   collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I tried compiling into objects but the linking still failed.</p>