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

Kiramin (Subscriptions) mk.subscribe at gmail.com
Thu Jul 22 03:02:44 CEST 2010


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";
}

BOOST_PYTHON_MODULE(hello)
{
    def("greet", greet);
}

int main()
{
PyImport_AppendInittab("hello", inithello);
Py_Initialize();
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
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
 <pbin\msvc-10.0\debug\threading-multi>BoostPy3DEngine.obj...
...skipped <pbin\msvc-10.0\debug\threading-multi>BoostPy3DEngine.pdb for
lack of
 <pbin\msvc-10.0\debug\threading-multi>BoostPy3DEngine.obj...
...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!

-Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100721/b4a09d2c/attachment.html>


More information about the Cplusplus-sig mailing list