title: C++ shared library undefined reference
body: <p>i'm having something like these files:</p>
  
  <p>libfoo.h</p>
  
  <pre><code>class foo
  {
  public:
  foo() = default;
  virtual ~foo();
  };
  </code></pre>
  
  <p>libfoo.cpp</p>
  
  <pre><code>#include "libfoo.h"
  
  foo::~foo() { /* code here */ }
  </code></pre>
  
  <p>test.cpp</p>
  
  <pre><code>#include &lt;libfoo.h&gt;
  int main()
  {
     foo f;
  }
  </code></pre>
  
  <p>i compile libfoo.h and libfoo.cpp into a shared library and all that is fine. 
  but when i then try to use the library in test.cpp i get undefined reference to the destructor ~foo().</p>
  
  <p>this error however does not occur if i define the destructor directly in libfoo.h. i have this problem with all functions defined outside the class in my library so im guessing it has something to do with the compilation process (it compiles fine however)</p>
  
  <p>i compile the library like this:</p>
  
  <pre><code>g++ -std=c++0x -Wall -Werror -fPIC  -c -o libfoo.o libfoo.cpp
  g++ -shared libfoo.o -o libfoo.so
  </code></pre>
  
  <p>any ideas as to what i might be doing wrong?
  (all the functions that i declare inclass, like template functions works fine and causes no undefined reference)</p>