By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,919 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,919 IT Pros & Developers. It's quick & easy.

a question about boost.python

P: n/a
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',
au*********************@gmail.com',
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::ostream& operator<<(std::ostream&,
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::obj ect>, 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::object]'
/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::object, 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::object::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

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.