Undefined reference in Eclipse of .h and .cpp files I'm trying to create a linked list for use on the Arduino, in the Eclipse IDE with the Arduino/Sloeber plugin. The linked list is written in a .h and .cpp file, and included locally in the project.



However, when building, I get the error undefined reference to Structures::LinkedList&lt;int&gt;::LinkedList().

And despite the fact that I've added the local folder to the list of includes (and it can find the top level file containing setup() and loop()), the problem persists;



My relevant file listings are below. Any ideas of what settings I can add to Eclipse in order to solve this? Potentially, could it be something to do with the use of template&lt;typename T&gt; in the header file?

Thanks very much,

David

FYI: This problem does not occur with the core libraries i.e. I can run examples like Serial and Blink.

My top level .cpp is pretty simple:

#include "LinkedList.h"
#include "RAStarSearch.h"
#include "Arduino.h"

using namespace Structures;
void setup() { }

void loop() {
  LinkedList&lt;int&gt; list = LinkedList&lt;int&gt;();
  return;
}


And the referenced .h is:

#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_
#include "Arduino.h"

namespace Structures {
template&lt;typename T&gt;
class LinkedList {
  public:
    /// Struct inside the class LinkedList
    struct Link {
      T value;
      Link *next;
    };

    LinkedList&lt;T&gt;(); ///&lt; Default constructor
    void addValue(T val); ///&lt; prepends new value at beginning of list
    T popValue(); ///&lt; returns first element and deletes Link.
    Link* peekLink(); ///&lt; Looks at first value
  private:
    Link *head; // this is the private member variable. It is just a pointer to the first Node
};
const int ERRNUM = 0x8000000; ///&lt;Error number used, as exceptions not supported
}
#endif /* LINKEDLIST_H_ */


EDIT 

On request I have included my code for LinkedList.cpp

#include "LinkedList.h"
#include "Arduino.h"

namespace Structures {
  template&lt;typename T&gt;
  LinkedList&lt;T&gt;::LinkedList() {
    head = NULL; // set head to NULL
  }
  template&lt;typename T&gt;
  void LinkedList&lt;T&gt;::addValue(T val) {
    Link *n = new Link();   // create new Node
    n-&gt;value = val;             // set value]

    if (head == NULL) { //i.e. if list is empty
      n-&gt;next = head;         // make the node point to the next node or NULL
      head = n;    // last but not least, make the head point at the new node.
    } else {
      Link *it = head;
      Link *oldIt = NULL;
      //TODO check edge cases i.e. insertion at beginning and end of list
      while (n-&gt;value &gt; it-&gt;value){ //until place in list is found, needs T to have &gt; operator
        oldIt = it;
        it = it-&gt;next;
      }
      oldIt-&gt;next = n; //Set pointer to n
      n-&gt;next = it; //Set n pointer to next
    }
  }
  template&lt;typename T&gt;
  T LinkedList&lt;T&gt;::popValue() {
    T retval = ERRNUM;
    if (head != NULL) {
      Link *n = head;
      retval = head-&gt;value;
      head = head-&gt;next;
      delete n;
    }
    return retval;
  }
  template&lt;typename T&gt;
  typename LinkedList&lt;T&gt;::Link* LinkedList&lt;T&gt;::peekLink() {
    return head;
  }
}
Have you tried placing the H file in the same folder as you main cpp file.  This should prove beyond all doubt that there is nothing wrong with the code (I can't see anything wrong).

I suspect its a path issue.  You need to check that Eclipse is setup up properly to source the libraries from you custom location.  Also it needs to be passing this location on to the compiler.  I don't know how to do that in Eclipse but Google should point you in the right direction. Try this http://forum.arduino.cc/index.php?topic=39972.0 ?

Also you might find it easier to specify the include files in the order system, 3rd party libraries, local libraries and then local include files.  This means that duplicate definition faults are reported against the files nearest to the ones you have written.  If you define time_t using your ordering the fault will be reported against  rather than your header file.

Also a using namespace foo statement removes the benefits that namespaces provide, so its best not to do it.

EDIT
Doh - I should have spotted this sooner.  Template classes have to have the functions inline not in a CPP file.  This is because the CPP file can't change what T is at compile time, but because the H file is included in the file it is used in when it is preprocessed the object represented by T can change. 
Basically inline your functions and it will work.