[C++-sig] boost.python errors on Linux

2010-12-11 Thread Max Stricker
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 

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

#include 
#include 
using namespace boost::python;

BOOST_PYTHON_MODULE(libboopyclass) {
boost::python::class_("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

Has anyone an idea whats going on here? How can I get this minimal example to 
work?


Regards,
Max

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python errors on Linux

2010-12-11 Thread 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

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

#include
#include
using namespace boost::python;

BOOST_PYTHON_MODULE(libboopyclass) {
boost::python::class_("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
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python errors on Linux

2010-12-11 Thread Max Stricker
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
>> 
>> class Foo {
>>  public:
>>  void bar() {
>>  std::cout<<  "Hello"<<  std::endl;
>>  }
>> };
>> 
>> #include
>> #include
>> using namespace boost::python;
>> 
>> BOOST_PYTHON_MODULE(libboopyclass) {
>>  boost::python::class_("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
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python errors on Linux

2010-12-11 Thread Stefan Seefeld

On 12/11/2010 11:10 AM, Max Stricker wrote:


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?


Your error message suggests the compiler couldn't find the Python 
headers. Do you have Python 2.6 installed ? Are the headers in 
/usr/include/python2.6 ? If not, you need to adjust your command line to 
whatever Python installation you have. (If you use system python 
packages, make sure to also install the "python-dev" package, which 
provides the headers as well as linkable DSOs.)


HTH,
Stefan

--

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

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python errors on Linux

2010-12-11 Thread scom

W dniu 2010-12-11 17:17, Stefan Seefeld pisze:

On 12/11/2010 11:10 AM, Max Stricker wrote:


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?


Your error message suggests the compiler couldn't find the Python 
headers. Do you have Python 2.6 installed ? Are the headers in 
/usr/include/python2.6 ? If not, you need to adjust your command line 
to whatever Python installation you have. (If you use system python 
packages, make sure to also install the "python-dev" package, which 
provides the headers as well as linkable DSOs.)


HTH,
Stefan



Hi,

I think there is still unnecessary space here: -I /usr/include/python2.6
Should be just -I/usr/include/python2.6

Cheers,
Sebastian



___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig