title: boost_python import error: module does not define init function
body: <p>First off: I looked at the related questions, but they are not very helpful unfortunately. I'm trying to wrap an enum and a class from an external library.</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;boost/python.hpp&gt;
  using namespace boost::python;
  
  #include &lt;libvpsc/rectangle.h&gt;
  using vpsc::Rectangle;
  using vpsc::Dim;
  
  BOOST_PYTHON_MODULE(adaptagrams)
  {
      enum_&lt;Dim&gt;("dim")
          .value("x", vpsc::XDIM)
          .value("y", vpsc::YDIM)
          .value("unset", vpsc::UNSET)
      ;
  
      class_&lt;Rectangle&gt;("Rectangle",
          init&lt;double, double, double, double, optional&lt;bool&gt; &gt;())
  
          .add_property("centerX", &amp;Rectangle::getCentreX)
          .add_property("centerY", &amp;Rectangle::getCentreY)
          .add_property("width", &amp;Rectangle::width, &amp;Rectangle::set_width)
          .add_property("height", &amp;Rectangle::height, &amp;Rectangle::set_height)
      ;
  }
  </code></pre>
  
  <p>and compile with:</p>
  
  <pre><code>g++ -fPIC -I/usr/include/python2.7 -c adaptagrams.cpp -o adaptagrams.o
  g++ -shared -Wl,-soname,adaptagrams.so -o adaptagrams.so adaptagrams.o -lpython2.7  -lboost_python -lvpsc
  </code></pre>
  
  <p>However, when I try to import the .so module, I get an error:</p>
  
  <pre><code>ImportError: dynamic module does not define init function (PyInit_adaptagrams)
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>Update:</strong> When I restart Python and try the import, the first error I get is:</p>
  
  <pre><code>ImportError: ./adaptagrams.so: undefined symbol: _ZN8topology13computeStressERKSt6vectorIPNS_4EdgeESaIS2_EE
  </code></pre>
  
  <p>When I try it again, the 2nd one is the dynamic import from above (2.7) and a segfault (3.2). Boost is compiled against both 2.7 and 3.2 and I am linking the right ones on each approach.</p>
  
  <p><strong>Update 2:</strong> The tutorial code from the boost_python page works:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;boost/python.hpp&gt;
  using namespace boost::python;
  
  struct Hello
  {
      Hello(std::string msg): msg(msg) {}
      void set(std::string msg) { this-&gt;msg = msg; }
      std::string greet() { return msg; }
      std::string msg;
  };
  
  BOOST_PYTHON_MODULE(constructor)
  {
      class_&lt;Hello&gt;("Hello", init&lt;std::string&gt;())
          .def("greet", &amp;Hello::greet)
          .def("set", &amp;Hello::set)
      ;
  }
  </code></pre>
  
  <p>Same compilation:</p>
  
  <pre><code>g++ -fPIC -I/usr/include/python2.7 -c constructor.cpp -o constructor.o
  g++ -shared -Wl,-soname,constructor.so -o constructor.so constructor.o -lpython2.7 -lboost_python
  </code></pre>