[C++-sig] Boost python simple interfacing

Cedric GESTES cedric.gestes at gmail.com
Mon Sep 23 10:04:00 CEST 2013


On Sep 23, 2013 1:48 AM, "Kassiopi Kassiopi2" <kassiopik at gmail.com> wrote:
>
> Hi,
>
> I want to call a c++ function from an embedded python shell, using boost
python. All the examples I've seen online describe how to expose a whole
class or some functions, but all cases refer to standalone parts of code.
> My case is different though. The function I want to expose is not
standalone, and has a dependency:
>
> ------- start of documentModule.cpp --------
> #include <commandManager.hpp>
> #include <boost/python.hpp>
>
> void newDocument( bool makeActive ) {
>      // depends on commandManager here
>     GetCommandMananager()->submitCommand( new newDocumentCmd( makeActive
) );
> }
>
> BOOST_PYTHON(documentModule) {
>     using namespace boost::python;
>     def( "newDocument", myCadLib::pythonCommands::newDocument,
arg("makeActive") );
> }
> ------- end of documentModule.cpp --------
>
> In reality the situation is more complicated and there are more
dependencies than the one mentioned above.
> After generating a .so file with distutils, when I start my application
and I attempt to load the module (.so file) in the embedded python shell I
get an undefined symbols error complaining about the commandManager class.
do you link the library containing commandManager to your python extension?
> Of course this is a reasonable request from python and I understand that.
However, I don't really care to generate a standalone python module per se.
I just want it to work in my application's embedded python shell.
Additionally, it wouldn't be meaningful to have the commandManager class
exposed as well, since this is part of my applications internal structure.
> Is what I am asking possible with boost python? In the past I have used
SWIG for that, and it generated some additional .cpp and .h files, as well
as a .py module. I can live with generating additional source and header
files if it is an issue for boost python and I don't care to have a
standalone python module, as long as it works inside my application.
> I couldn't find anything online as well. All examples I could find where
similar to the boost python tutorial, with standalone parts of code.
>
> Thank you in advance.
>
>
>
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20130923/e0df7f04/attachment.html>


More information about the Cplusplus-sig mailing list