title: Using Ctypes to call complicated c++ code
body: <p>My question is based on this <a href="https://stackoverflow.com/a/145649/8408902">example</a>. What's different is that in my C++ code, I have a function that initiates an object of a self-defined class <em>within that function</em>. In my python code, I simply want to call that function. I don't need to create an object of the self-defined class in Python. For example, there are three files in my C++ code</p>
  
  <p><strong>foo.h</strong></p>
  
  <pre><code>class foo {
  
  public: 
          foo();
          void bar();
          int a;
  
  
  };
  </code></pre>
  
  <p><strong>foo.cpp</strong></p>
  
  <pre><code>extern "C" {
      foo::foo () {
        a = 5;
      }
  
  
      void foo::bar(){
              std::cout &lt;&lt; "Hello" &lt;&lt; std::endl;
      };
  }
  </code></pre>
  
  <p><strong>mainFunc.cpp</strong></p>
  
  <pre><code>extern "C" {
      void printStuff (int addNum) {
          foo fooArg;
          fooArg.a = fooArg.a + addNum;
          std::cout&lt;&lt;"Printing..."&lt;&lt;std::endl;
          std::cout&lt;&lt;fooArg.a&lt;&lt;std::endl;
      }
  }
  </code></pre>
  
  <p>In my Python code, I want to create a Python function that calls <code>printStuff</code> in <code>mainFunc.cpp</code>. I don't need to initiate an object of <code>foo</code> in Python. However, two questions:</p>
  
  <p>(1) Did I use <code>extern "C"</code> correctly?</p>
  
  <p>(2) How should I compile these three files into a shared library? I use g++.</p>