title: Compile python code and link it to C++ program?
body: <p>I am well aware of the many possibilities that exist to allow C code to run python code, and vice versa (Cython, Boost.Python, ...). However, unless I am mistaken, all those approaches merely "call" the relevant python scripts and manage the interactions between the C program and the python script. Therefore, an installation of python is required.</p>
  
  <p>In my situation, I would like a stand-alone solution, where my python code can be somehow compiled and linked to my main C++ program. I had hopes with Cython, as it allowed me to compile my script and create a .so file. However, I don't seem to have been able to "link" that .so file to my C++ program. I attempted the following:</p>
  
  <p>A simple python script containing a function multiply(a,b) which returns a*b ; I created a libmultiply.so file using cython.
  A short Cpp file which outputs the result of multiply(5,2):</p>
  
  <pre><code>int multiply(int, int);
  
  int main()
  {
      std::cout &lt;&lt; multiply(5,2) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>I build by doing : <strong>g++ test.cpp -L/home/jerome/ -lmultiply</strong></p>
  
  <p>Which gives me the error :</p>
  
  <pre><code>test.cpp:(.text+0x2b): undefined reference to `multiply(int, int)'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I am not sure if what I tried makes sense, but hopefully it gives you an idea of what I would like to achieve.</p>