[C++-sig] problems compiling and embedding, boost-python
Benjamin Collar
collar at gamic.com
Mon Oct 13 15:53:25 CEST 2003
Greetings
I'm trying for the first time to embed the python interpreter in my
application. I'm using boost from today's CVS and gcc 3.3.1. I'm just trying
to follow the example from the boost-python documentation. I've got two
problems, one of which I solved and one I haven't. Any help would be
appreciated.
When I try this:
handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get()) ));
handle<>( PyRun_String("hello = file('hello.txt', 'w')\n"
"hello.write('Hello world!')\n"
"hello.close()", Py_file_input,
main_namespace.get(), main_namespace.get()) );
I get:
main.cc: In function `int main(int, char**)':
main.cc:37: error: no matching function for call to `
boost::python::handle<PyObject>::handle(const char[73], int, PyObject*,
PyObject*)'
/home/bc/HEAD/muranxx3/include/boost/python/handle.hpp:129: error: candidates
are:
boost::python::handle<T>::handle(boost::python::detail::borrowed_reference_t*)
[with T = PyObject]
/home/bc/HEAD/muranxx3/include/boost/python/handle.hpp:110: error:
boost::python::handle<T>::handle(const boost::python::handle<T>&) [with
T
= PyObject]
/home/bc/HEAD/muranxx3/include/boost/python/handle.hpp:187: error:
boost::python::handle<T>::handle() [with T = PyObject]
No Problem, all I have to do is replace the last function with:
handle<> x(PyRun_String(...)
If I declare a variable it compiles fine.
However, moving right along in the documentation, if I try to compile this:
handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
dict main_namespace(handle<>(borrowed( PyModule_GetDict(main_module.get())
)));
handle<>( PyRun_String("result = 5 ** 2", Py_file_input,
main_namespace.ptr(), main_namespace.ptr()) );
int five_squared = extract<int>( main_namespace["result"] );
I get this, which I do not know how to resolve:
main.cc: In function `int main(int, char**)':
main.cc:33: error: variable declaration is not allowed here
main.cc:35: error: request for member `ptr' in `main_namespace()', which is of
non-aggregate type `boost::python::dict ()()'
main.cc:35: error: request for member `ptr' in `main_namespace()', which is of
non-aggregate type `boost::python::dict ()()'
main.cc:36: error: invalid types `boost::python::dict ()()[const char[7]]' for
array subscript
main.cc:36: warning: unused variable `int five_squared'
What's up with this last one?
Thanks
Ben
--
----------------------------------------
(o__ Benjamin Collar
//\ GAMIC mbH ++49 (0)241 889 110
V_/_ Developer/System Administrator
To know recursion, you must first know recursion
More information about the Cplusplus-sig
mailing list