Keith MacDonald wrote:
I've tried to merge the Boost.Python tutorials for embedding and extending (see below), to end up with an executable that does both. The script fails to import "hello", so BOOST_PYTHON_MODULE is presumably not the correct way to do it. What is?
Thanks, Keith MacDonald
====== The C++ code ====== #include
using namespace boost::python;
char const* greet() { return "hello, embedded world"; }
BOOST_PYTHON_MODULE(hello) { def("greet", greet); }
int main() { Py_Initialize();
object main_module(( handle<>(borrowed(PyImport_AddModule("__main__")))));
object main_namespace = main_module.attr("__dict__");
try { handle<> ignored((PyRun_String( "import hello\n"
I think you need something like: if (PyImport_AppendInittab("hello", init_hello) == -1) throw std::runtime_error("Failed to add embedded_hello to the interpreter's builtin modules"); after Py_Initialize - Volodya