On 12/11/2010 07:29 AM, Max Stricker wrote:
Hi,

i need to expose some C++ methods to python and came accross boost.python.
I installed libboost-python1.42-dev on an Ubuntu machine and tried to work with 
a
simple program found in the docs:

#include<iostream>

class Foo {
        public:
                void bar() {
                        std::cout<<  "Hello"<<  std::endl;
                }
};

#include<boost/python.hpp>
#include<Python.h>
using namespace boost::python;

BOOST_PYTHON_MODULE(libboopyclass) {
        boost::python::class_<Foo>("Foo")
                .def("bar",&Foo::bar);
}


I build it using: gcc foo.cpp  -I /usr/include/python2.6 -l python2.6 -l 
boost_python

I get a huge error list indicating that objects like PyObject or PyTypeObject 
could not be found,
the detailed output is available here: http://pastebin.com/TyN9dZ09

Add the '-shared' option (to indicate that you want to build a shared library), remove the space in '-l boost_python', and specify the output filename (such as '-o foo.so'). Finally, you should compile with g++, not gcc.
For example:

g++ -shared -o foo.so foo.cpp -I/usr/include/python2.6 -lpython2.6 -lboost_python

    Stefan


--

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to