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:ython;
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:stream& operator<<(std:stream&,
Rational)':
Rational.cpp:10: warning: unused parameter `Rational r'
/usr/include/boost/python/def_visitor.hpp: In static member function
`static
void boost:ython::def_visitor_access::visit(const V&, classT&)
[with V =
boost:ython::def_visitor<boost:ython::api:bject>, classT =
boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>]
':
/usr/include/boost/python/def_visitor.hpp:67: instantiated from `void
boost:ython::def_visitor<DerivedVisitor>::visit(classT&) const [with
classT = boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>, DerivedVisitor =
boost:ython::api:bject]'
/usr/include/boost/python/class.hpp:225: instantiated from
`boost:ython::class_<T, X1, X2, X3>& boost:ython::class_<T, X1, X2,
X3>::def(const boost:ython::def_visitor<Derived>&) [with Derived =
boost:ython::api:bject, W = Rational, X1 =
boost:ython::detail::not_specified, X2 =
boost:ython::detail::not_specified, X3 =
boost:ython::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:ython::api:bject::visit(boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>&) const'
make: *** [Rational.o] Error 1
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:ython;
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:stream& operator<<(std:stream&,
Rational)':
Rational.cpp:10: warning: unused parameter `Rational r'
/usr/include/boost/python/def_visitor.hpp: In static member function
`static
void boost:ython::def_visitor_access::visit(const V&, classT&)
[with V =
boost:ython::def_visitor<boost:ython::api:bject>, classT =
boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>]
':
/usr/include/boost/python/def_visitor.hpp:67: instantiated from `void
boost:ython::def_visitor<DerivedVisitor>::visit(classT&) const [with
classT = boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>, DerivedVisitor =
boost:ython::api:bject]'
/usr/include/boost/python/class.hpp:225: instantiated from
`boost:ython::class_<T, X1, X2, X3>& boost:ython::class_<T, X1, X2,
X3>::def(const boost:ython::def_visitor<Derived>&) [with Derived =
boost:ython::api:bject, W = Rational, X1 =
boost:ython::detail::not_specified, X2 =
boost:ython::detail::not_specified, X3 =
boost:ython::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:ython::api:bject::visit(boost:ython::class_<Rational,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified,
boost:ython::detail::not_specified>&) const'
make: *** [Rational.o] Error 1