title: Wrapping different C API implementations in C++
body: <p>assume we were using gcc/g++ and a C API specified by a random committee. This specification defines the function</p>
  
  <pre><code>void foo(void);
  </code></pre>
  
  <p>Now, there are several implementations according to this specification. Let's pick two as a sample and call them <code>nfoo</code> and <code>xfoo</code> (provided by libnfoo and libxfoo as static and dynamic libraries respectively).</p>
  
  <p>Now, we want to create a C++ framework for the <code>foo</code>-API. Thus, we specify an abstract class</p>
  
  <pre><code>class Foo
  {
    public:
      virtual void foo(void) = 0;
  };
  </code></pre>
  
  <p>and corresponding implementations</p>
  
  <pre><code>#include &lt;nfoo.h&gt;
  #include "Foo.h"
  
  class NFoo : public Foo
  {
    public:
      virtual void foo(void) 
      {
        ::foo(); // calling foo from the nfoo C-API
      }
  };
  </code></pre>
  
  <p>as well as</p>
  
  <pre><code>#include &lt;xfoo.h&gt;
  #include "Foo.h"
  
  class XFoo : public Foo
  {
    public:
      virtual void foo(void) 
      {
        ::foo(); // calling foo from the xfoo C-API
      }
  };
  </code></pre>
  
  <p>Now, we are facing a problem: <strong>How do we create (i.e. link) everything into one library?</strong></p>
  
  <p>I see that there will be a symbol clash with the <code>foo</code> function symbols of the C API implementations.</p>
  
  <p>I already tried to split the C++ wrapper implementations into separate static libraries, but then I realized (again) that static libraries is just a collection of unlinked object files. So this will not work at all, unless there is a way to fully link the C libraries into the wrapper and remove/hide their symbols.</p>
  
  <p>Suggestions are highly appreciated.</p>
  
  <p><strong>Update:</strong> Optimal solutions should support both implementations at the same time.</p>
  
  <p>Note: The code is not meant to be functional. Perceive it as pseudo code.</p>