a question about boost.python

L

Li Daobing

I can't use .def(str(self))
I write a simple example, without `str', I can build it well, but with
this one, I can't build

//Rational.cpp
#include <boost/python.hpp>
#include <iostream>

using namespace std;
using namespace boost::python;

class Rational
{};

ostream& operator<<(ostream& os, Rational r){
return os;
}
BOOST_PYTHON_MODULE(Rational)
{
class_<Rational>("Rational")
..def(str(self)) // __str__
;
}
// end.

I don't know how to write Jamfile, so I write a Makefile, it works if i
don't use .def(str(self))

# Makefile
CC = g++

CFLAGS = -Wall -W -fPIC -I/usr/include/boost \
-I/usr/include/python2.3 -DBOOST_PYTHON_DYNAMIC_LIB \
-O2

LDFLAGS = -L/usr/local/lib -lboost_python -L/usr/lib/python2.3 \
-Wl,-rpath-link,. -fPIC


CXXFLAGS = $(CFLAGS)

SLIB = hello.so Rational.so

all: $(SLIB)

%.so : %.o
/usr/bin/objcopy --set-section-flags .debug_str=contents,debug
$^
$(CC) $(LDFLAGS) $^ -shared -o $@

clean :
rm -f $(WORLD) $(OBJS)
# end.

or a simple setup.py, it also works if I don't use `str'

# setup.py
from distutils.core import setup, Extension

ext_modules = [Extension('Rational', ['Rational.cpp'],
define_macros=[('BOOST_PYTHON_DYNAMIC_LIB',
None)],
libraries=['boost_python'])]


setup(name="itcc",
version="0.2.2",
author='Li Daobing',
author_email='(e-mail address removed)',
ext_modules = ext_modules
)
# end.

This is the error message:
$ make
g++ -Wall -W -fPIC -I/usr/include/boost -I/usr/include/python2.3
-DBOOST_PYTHON_DYNAMIC_LIB -O2 -c -o Rational.o Rational.cpp
Rational.cpp: In function `std::eek:stream& operator<<(std::eek:stream&,
Rational)':
Rational.cpp:10: warning: unused parameter `Rational r'
/usr/include/boost/python/def_visitor.hpp: In static member function
`static
void boost::python::def_visitor_access::visit(const V&, classT&)
[with V =
boost::python::def_visitor<boost::python::api::eek:bject>, classT =
boost::python::class_<Rational,
boost::python::detail::not_specified,
boost::python::detail::not_specified,
boost::python::detail::not_specified>]
':
/usr/include/boost/python/def_visitor.hpp:67: instantiated from `void
boost::python::def_visitor<DerivedVisitor>::visit(classT&) const [with
classT = boost::python::class_<Rational,
boost::python::detail::not_specified,
boost::python::detail::not_specified,
boost::python::detail::not_specified>, DerivedVisitor =
boost::python::api::eek:bject]'
/usr/include/boost/python/class.hpp:225: instantiated from
`boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2,
X3>::def(const boost::python::def_visitor<Derived>&) [with Derived =
boost::python::api::eek:bject, W = Rational, X1 =
boost::python::detail::not_specified, X2 =
boost::python::detail::not_specified, X3 =
boost::python::detail::not_specified]'
Rational.cpp:15: instantiated from here
/usr/include/boost/python/def_visitor.hpp:31: error: no matching
function for
call to
`boost::python::api::eek:bject::visit(boost::python::class_<Rational,
boost::python::detail::not_specified,
boost::python::detail::not_specified,
boost::python::detail::not_specified>&) const'
make: *** [Rational.o] Error 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top