title: Create shared library from cpp files and static library with g++
body: <p>Just like title says, I want to create shared library from three cpp files and with some static library.</p>
  
  <p>Basicly I want to do this</p>
  
  <pre><code>g++ libProject.so file1.cpp file2.cpp file3.cpp -I /usr/local/include -L /usr/local/lib -lAlgatorc 
  </code></pre>
  
  <p>This is my file1.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;TestSetIterator.hpp&gt;
  
  class SortingTestSetIterator : public TestSetIterator {
  public: 
      TestCase *get_current(){
           //TODO: implement method
           return nullptr; 
      }
  };
  </code></pre>
  
  <p>This is my file2.cpp</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;TestCase.hpp&gt;
  #include&lt;Entity.hpp&gt;
  #include&lt;ParameterSet.hpp&gt;
  
  class SortingTestCase : public TestCase {
  public: 
      std::string print() { 
           //TODO: implement method
          return "";
      }
  };
  </code></pre>
  
  <p>And this is my file3.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;AbsAlgorithm.hpp&gt;
  #include "SortingTestCase.cpp"
  class SortingAbsAlgorithm : public AbsAlgorithm {
  private: 
      SortingTestCase Sorting_test_case;
  public:
      bool init (TestCase &amp;test) {
           //TODO: implement method
           return true; 
      }
  
      void run() {
           //TODO: Implement method 
      }
  
      void done() {
           //TODO: Implement method 
      }
  };
  </code></pre>
  
  <p>I think that I need to create three .o files (file1.o file2.o file3.o) and then combine them like this </p>
  
  <pre><code>ld -r file1.o file2.o file3.o -o file.o
  </code></pre>
  
  <p>When I have file.o I suppose that then I need to say this:</p>
  
  <pre><code>g++ -shared -o libProject.so file.o
  </code></pre>
  
  <p>but I don't know how to compile .cpp files into .o files.
  I know I can do it like this</p>
  
  <pre><code>g++ -std=gnu++11 -o file1.o -fPIC -c file1.cpp -I /usr/local/include
  </code></pre>
  
  <p>but I must also provide static library to this command, because file1.cpp (and other files) inherits class that is defined in /usr/local/include/TestSetIterator.hpp but is implemented in /usr/local/lib/libAlgatorc.a Because of -c I can't say -L /usr/local/lib -lAlgatorc</p>
  
  <p>At the end, I want shared library of this three classes so that in main function I can load this library into my program and that I can call methods from this three classes. So, I want shared library with all symbols from static library (libAlgatorc.a) and from all three cpp files (file1.cpp, file2.cpp and file3.cpp)</p>
  
  <p>I am using Ubuntu 12.04 x64.</p>
  
  <pre><code>&gt; g++ --version
  g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
  Copyright (C) 2013 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>