Am 11.12.2010 um 15:03 schrieb Stefan Seefeld:

> 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

I tried your suggestions but it leads to the same error message (using g++ 
-shared foo.cpp -o foo.so  -I /usr/include/python2.6 -lpython2.6 
-lboost_python).
Could there be something wrong with the installation?
In the meantime I tried it on an OSX machine, installed boost 1.45 by hand 
(using bjam --with-python). The error is exactly the same.
I suppose the code should be fine as its from the docs. Am I missing an 
important step?

Max

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

Reply via email to