[C++-sig] Need help with simple boost embedded python program

David Aldrich David.Aldrich at EU.NEC.COM
Thu Jul 22 15:50:53 CEST 2010

I'm new to boost.python so am just a beginner. But I built boost.python with bjam and then built my C++ application with MSVC 2008 (not bjam). Worked fine.


From: cplusplus-sig-bounces+david.aldrich=eu.nec.com at python.org [mailto:cplusplus-sig-bounces+david.aldrich=eu.nec.com at python.org] On Behalf Of Kiramin (Subscriptions)
Sent: 22 July 2010 02:03
To: cplusplus-sig at python.org
Subject: [C++-sig] Need help with simple boost embedded python program

I can't seem to get this to work:
This little program just embeds python, creates a module using boost, and attempts to add it to the list of built-in modules.

#include <boost/python.hpp>
using namespace boost::python;

char const* greet()
   return "hello, world";

    def("greet", greet);

int main()
          PyImport_AppendInittab("hello", inithello);
          return 0;

But when I attempt to build using bjam, I get:

...found 1629 targets...
...updating 3 targets...
compile-c-c++ bin\msvc-10.0\debug\threading-multi\BoostPy3DEngine.obj
BoostPy3DEngine.cpp(17) : error C2065: 'inithello' : undeclared identifier

    call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
cl /Zm800 -nologo @"bin\msvc-10.0\debug\threading-multi\BoostPy3DEngine.obj.rsp"

...failed compile-c-c++ bin\msvc-10.0\debug\threading-multi\BoostPy3DEngine.obj...
...skipped <pbin\msvc-10.0\debug\threading-multi>BoostPy3DEngine.exe for lack of
...skipped <pbin\msvc-10.0\debug\threading-multi>BoostPy3DEngine.pdb for lack of
...failed updating 1 target...
...skipped 2 targets...

My understanding is that the BOOST_PYTHON_MODULE macro is supposed to create the inithello function when it builds the hello module... but the compiler doesn't seem to be able to find it.

The above code compiles without complaint if I leave out the line:
PyImport_AppendInittab("hello", inithello);

I am using bjam with the --toolset=msvc switch (its the only way I know how to build with boost).  And I have MSVC version 10.0.30319.1 installed, and this is a Windows XP machine.

Anyone know what might be causing the above error?

Thanks for any help you can give!


Click here<https://www.mailcontrol.com/sr/PLJy!+rMVeHTndxI!oX7UqMEQvnfkQd8IoSZeSiUao33IuUnm05pATKrPOVDpyxkMZUh17DZ8VVhUYCj!eKynw==> to report this email as spam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100722/7abb86c8/attachment.html>

More information about the Cplusplus-sig mailing list