title: Boost Python and Cmake with Ubuntu and Python3.5
body: <p>I'm having issues getting Boost Python to compile with Cmake. Everything works fine when compiled manually. Here is how I set everything up and ran it :</p>
  
  <ul>
  <li><p>Install python 3.5 :</p>
  
  <pre><code>sudo apt-get install python3-dev
  </code></pre></li>
  <li><p>Download the lastest version of Boost from <a href="http://www.boost.org/" rel="nofollow noreferrer">http://www.boost.org/</a></p></li>
  <li><p>Run bootstrap with correct flags :</p>
  
  <pre><code>./bootstrap.sh --with-python=python3.5
  </code></pre></li>
  <li><p>Compile Boost in directory :</p>
  
  <pre><code>./b2
  </code></pre></li>
  <li><p>Install Boost headers to /usr/local/include and Boost libs to /usr/lib/x86_64-linux-gnu</p>
  
  <pre><code>sudo ./b2 install
  </code></pre></li>
  <li><p>Compile example with proper flags :</p>
  
  <pre><code>g++ greet_binding.cpp -I/usr/include/python3.5m -I/usr/local/include -lboost_python-py35 -lpython3.5m -o greet.so -shared -fPIC
  </code></pre></li>
  <li><p>Start Python interpreter :</p>
  
  <pre><code>$ python3
  
  import greet
  
  greet.say_greeting("Foo")
  
  Hello, Foo!
  </code></pre></li>
  </ul>
  
  <p>greet_binding.cpp :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/python/def.hpp&gt;
  #include &lt;boost/python/module.hpp&gt;
  
  using namespace std;
  namespace bp = boost::python;
  
  void say_greeting(const char* name)
  {
          cout &lt;&lt; "Hello, " &lt;&lt; name &lt;&lt; "!\n";
  }
  
  BOOST_PYTHON_MODULE(greet)
  {
          bp::def("say_greeting", say_greeting);
  }
  </code></pre>
  
  <p>However, when I try to set up a simple CmakeLists.txt file to compile it, I get an error when importing the compiled .so from Python.</p>
  
  <p>CMakeLists.txt :</p>
  
  <pre><code>cmake_minimum_required( VERSION 2.8.3 )
  project ( boost-python-3.5-examples )
  
  set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
  -g -std=c++14 \
  -I/usr/include/python3.5m \
  -I/usr/local/include \
  -lboost_python-py35 \
  -lpython3.5m \
  -fPIC" )
  
  add_library( greet SHARED greet_binding.cpp )
  </code></pre>
  
  <p>This compiles fine, then I start the python interpreter in the build directory :</p>
  
  <pre><code>$ python3
  
  import libgreet
  
  Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ImportError: /home/james/Programming/boost-python-3.5-examples/build/libgreet.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
  </code></pre>
  
  <p>What am I doing wrong?</p>