title: undefined reference to [class::function] / undefined reference to typeinfo for [class]
body: <p>I have a base class defined with 3 pure virtual functions:</p>
  
  <pre><code>class Baseclass
  {
  public:
      virtual ~Baseclass() {};
      virtual void getSomething(std::vector&lt;uint8_t&gt;&amp; something) const = 0;
      virtual uint8_t classLength() const = 0;
  }
  </code></pre>
  
  <p>And from that I derive 2 other classes</p>
  
  <pre><code>class DerivedA : public Baseclass
  {
  public:
      DerivedA();
      ~DerivedA();
      bool setParamA(const std::vector&lt;uint8_t&gt; value);
      bool setParamB(const std::vector&lt;uint8_t&gt; value);
      void getSomething(std::vector&lt;uint8_t&gt;&amp; something) const;
      uint8_t classLength() const;
  private:
      uint8_t mParamA;
      uint8_t mParamB;
  }
  </code></pre>
  
  <p>The second class is analog to the first.</p>
  
  <p>This compiles and works perfectly for my unit tests (regular allocation, no pointers).</p>
  
  <p>Now i try to integrate this (it is compiled as a library) in the rest of my code like this:</p>
  
  <pre><code>std::shared_ptr&lt;Baseclass&gt; object;
  object = std::make_shared&lt;DerivedA&gt;(); // 1
  std::dynamic_pointer_cast&lt;DerivedA&gt;(object)-&gt;setParamA(...) // 2
  </code></pre>
  
  <p>Compilation goes perfectly but linking gives following errors:</p>
  
  <p>undefined reference to typeinfo for [class] (line 1)<br>
  undefined reference to [class::function] (line 2)</p>
  
  <p>on this command</p>
  
  <pre><code>g++-4.7  -o ../Deliv/GnuDebug/ClassesTest ../Deliv/GnuDebug/buildsupport/cppunit/mainCB.o   -pthread  ../../../../../../3rdparty/libcppunit/obj/native-gcc/libcppunit/src/cppunit/.libs/libcppunit.a ../../../Classes/Deliv/GnuDebug/libClasses.a
  </code></pre>
  
  <p>Another strange thing is that it only produces this error for 1 of the derived classes and that 1 of the derived classes has worked in the above construction for allocation of the shared_ptr</p>
  
  <p>I have no clue what could be wrong here, if anyone could point me in the right direction i will be eternally grateful</p>
  
  <p><strong>edit with solution:</strong></p>
  
  <p>I found the solution to my problem so for further reference:</p>
  
  <p>Setup:</p>
  
  <pre><code>Baseobject, DerivedA, DerivedB -&gt; libObjects.a
  Functionality using DerivedA, DerivedB -&gt; libFunctionality.a
  TestFunctionality using Functionality -&gt; Error
  </code></pre>
  
  <p>Problem:</p>
  
  <p>That the linker was trying to link to libFunctionality before It knew libObjects and therefore giving errors.</p>
  
  <p>Solution:</p>
  
  <p>Change the order in which the libraries get linked.</p>
  
  <p>Strange behavior:</p>
  
  <p>I only got errors for DerivedA, not for DerivedB. If I would comment out the code using DerivedA, TestFunctionality would compile and run without errors.<br>
  Has anyone got a clue to why this is ?</p>
  
  <p>And can someone verify my explanation for correctness and perhaps point me to some article explaining this problem ?</p>