Hi Faheem, I ran into that too. In short, the line with "handle<>( PyRun_String" isn't being understood how you want it too... You can surround that expression with parenthesis, and it should work: (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()) )); Chad On Mon, 28 Jun 2004 04:26:19 +0000 (UTC), Faheem Mitha <faheem@email.unc.edu> wrote:
Dear People,
When trying to compile the following code (direct from sample code in the turorial) I get these errors. I am using distutils and realise my flags may not be exactly right, but the compiler seems to be saying it cannot find the correct version of handler to use! This does not look like it has anything to do with the correct flags, though I could be wrong.
I'm trying to call the interpreter from within a extension module. Is there any reason I can't do this? Thanks in advance.
Faheem.
building 'embed' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.3 -c embed.cc -o /tmp/temp.linux-i686-2.3/embed.o -Wl,-E embed.cc: In function `void foo()': embed.cc:35: error: no matching function for call to ` boost::python::handle<PyObject>::handle(const char[73], int, PyObject*, PyObject*)' /usr/include/boost/python/handle.hpp:129: error: candidates are: boost::python::handle<T>::handle(boost::python ::detail::borrowed_reference_t*) [with T = PyObject] /usr/include/boost/python/handle.hpp:110: error: boost::python::handle<T>::handle(const boost::python::handle<T>&) [with T = PyObject] /usr/include/boost/python/handle.hpp:205: error: boost::python::handle<T>::handle() [with T = PyObject] error: command 'gcc' failed with exit status 1 make: *** [embed.so] Error 1 make: Target `all' not remade because of errors.
Compilation exited abnormally with code 2 at Mon Jun 28 00:02:00
************************************************************************* embed.cc ************************************************************************* #include <boost/python.hpp> #include <boost/scoped_ptr.hpp> #include <python2.3/Python.h> #include <pythonrun.h> using namespace boost::python;
void foo() { Py_Initialize();
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()) );
Py_Finalize(); }
BOOST_PYTHON_MODULE(embed) { def("foo",foo); } *************************************************************************
_______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig