I've been looking at using boost-python, I would like to share results.
Firstly, why not just use the standard C-API for bridging between C and Python https://docs.python.org/3.4/extending/index.html ?
Mainly because it is a bit clunky, there is going to be some amount of boilerplate and repetition. How to transfer umpteen datatypes like lists and dictionaries between C and Python?
Also there are multithreading issues. What if several C++ threads independently call different functions in the Python runtime? How about if one C++ thread locks the runtime, calls a Py function, but that function then calls back out to C++? In that case the runtime surrenders the lock, so the original C++ thread maybe thinking it is still locking the runtime but it isn't.
I'm not sure to tell the truth. And I think actually it may be the best way to go; something simple and platform independent.
Boost is a huge C++ library, and boost-python digs its tendrils deep into Boost. "According to http://www.pdimov.com/tmp/report-d5ca5be/module-levels.html Boost.Python is at module level 11, roughly requiring half of Boost" (thanks jhunold on irc.freenode.net #boost)
This means there is no chance of using Boost's BCP tool to just extract the necessary files, Boost is >300Megs and it is going to pull out a sizeable chunk. So the only practical solution will be to use boost-python library.
On OS X I have homebrew, and it is as simple as 'brew install boost-python' then sudo find / -iname "libboost_python*". Note the '*-mt' mean multithreaded.
But realise that to make this multiplatform, we would need to build boost-python on all five platforms just as we have to build python on all five platforms. And it looks like a rocky ride for mobile platforms. (Android: http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/).
So that may be a showstopper right there. At least building Python on all five platforms is already being done by the Kivy team. But for boost-python no such luck.
Anyway, trying it out on OS X, using an empty Xcode command line project, I straightaway run into a bug: http://boost.2283326.n4.nabble.com/boost-python-embedding-error-runtime-Mac-OS-X-1-38-td2702075.html
And there I am currently stuck. I don't want to have to dig into the source code for Boost.Python. But that may be the only way through.
What other options?
I have put some links up at http://mathpad.wikidot.com/embedpython
ffpython ( http://www.codeproject.com/Tips/587652/Cplusplus-Easier-to-Embed-Pytho ) looks interesting, although it doesn't seem to be actively maintained and it doesn't support Python 3.x
A couple of articles that look worth reading:
http://realmike.org/blog/2012/07/08/embedding-python-tutorial-part-1/
http://codextechnicanum.blogspot.co.uk/2013/12/embedding-python-in-c-converting-c.html
At the moment I am more interested in non-boost alternatives, mainly because it props the door open for a multiplatform solution, and also because it wouldn't run the risk of hitting bugs deep in boost. Also, boost.python provides way more than is needed for a simple bridge.
π