473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

a question about boost.python

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
0 2108

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Link | last post by:
Dear sir, I am used to developing C program on MSVC7.0 platform. This is my first time to use Python for calling by C program. Now, it is hard to deal with the problem about extracting the...
0
by: Andrew Ayre | last post by:
Hi, I can't seem to get the library built, and any help is greatly appreciated. Here is the info: Windows XP Borland C++ Builder 5 Latest Boost source code (downloaded at the weekend) Windows...
1
by: Max Wilson | last post by:
Hi, Has anyone here built Boost.Python modules under MinGW? I'm trying to build the Boost.Python tutorial under MinGW and getting an error that says it depends on MSVC, which puzzles me because...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
4
by: Shawn McGrath | last post by:
Hi, I'm trying to expose a C++ class' internals to python via boost::python. I can do integer/boolean functions fine, but as soon as I do a string get/set it craps out. ...
2
by: mr_gees100_peas | last post by:
Hi, I've been trying for days to make either boost.python or swig to work for me. The one I have gotten the closest to is boost. Note that this is for windows XP. I'm not much of an unix person...
0
by: devito | last post by:
hi there, for some days i try to build the boost.python tutorial "hello world" without bjam on winxp by using mingw. so i wrote a *.bat-file like the following: // --- snip...
3
by: Till Kranz | last post by:
Hi, I tried to get started with Boost.Python. unfortunately I never used the bjam build system before. As it is explained in the documentation I tried to adapt the the files form the examples...
0
by: Stodge | last post by:
Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.