I recently installed Boost using MacPorts, with the intent to do some Python embedding in C++. I then decided to check if I configured Xcode correctly with an example found on Python's website:
#include <boost/python.hpp>
using namespace boost::python;
int main( int argc, char ** argv )
{
try
{
Py_Initialize();
object main_module(handle<>(borrowed(PyImport_AddModule("__main__"))));
object main_namespace = main_module.attr("__dict__");
handle<> ignored(PyRun_String("print \"Hello, World\"",
Py_file_input,
main_namespace.ptr(),
main_namespace.ptr()));
}
catch( error_already_set )
{
PyErr_Print();
}
}
It compiles correctly, but when I launch it, the call to attr() throws an exception, and the resulting error message is "TypeError: attribute name must be string, not 'str'". Which suspiciously sounds like a placeholder.
I looked it up on Google, but no luck.
I use Boost v1.39, Python 2.5 and GCC 4.0, on Leopard.
Your code worked for me with the following configuration:
Compiled using:
g++ -I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ -I/usr/local/boost/1_41_0/include -L/usr/local/boost/1_41_0/lib/ -boost_python -L/usr/lib/python2.6/config -lpython2.6 test.cpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With