473,385 Members | 2,005 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,385 software developers and data experts.

Boost Python Issue

I was wondering if someone here could help me with a problem I'm having
building Python extensions with the Boost.Python library.
Basically, if I have a wrapper class with something like this:

string TestFunc()
{
return "Hello World";
}

BOOST_PYTHON_MODULE(TestClass)
{
def("TestFunc",TestFunc);
}
It compiles and I can use it without a problem. However, when I try to
wrap a class with code like this:

class TestClass
{
public:
TestClass() {};
~TestClass() {};
string TestFunction(){return "Hello World";};
};

BOOST_PYTHON_MODULE(TestClass)
{
class_<TestClass>("TestClass")
.def("TestFunction",&TestClass.TestFunction)
;
}
I get the following error:
vc-C++
bin\PythonTest\TestClass.pyd\vc-8_0\debug\threading-multi\TestClass.obj
TestClass.cpp
TestClass.cpp(27) : error C2976: 'boost::python::class_' : too few
template arguments

c:\Development\Boost\boost_1_33_1\boost/python/def_visitor.hpp(14) :
see declaration of 'boost::python::class_'
TestClass.cpp(27) : error C2440: '<function-style-cast>' : cannot
convert from 'const char [10]' to 'boost::python::class_'
Source or target has incomplete type

I'm using Visual Studio 2005 Express Edition (I get the same error with
2003 Professional), and am using bJam to build the extension.

Does anyone have any idea what's causing this?

Aug 31 '06 #1
4 2255
I believe this is more of a tools/compiler issue than a coding issue.

If you are using the pre-built BOOST.Python library you get compile
mismatches. I am not a Windows Visual Studio programmer (barely a
programmer), I am probably not using the correct terminology.

There are some settings for the threading type, debugging modes, etc.
If these don't match between you VC compilation and the BOOST library
complitation you can get those errors.

I had similar problems and it took me forever to figure it out.

Let me know if this helps, look at the command line from visual studio
and compare it to your command line from the Bjam build.

JDJMSon wrote:
I was wondering if someone here could help me with a problem I'm having
building Python extensions with the Boost.Python library.
Basically, if I have a wrapper class with something like this:

string TestFunc()
{
return "Hello World";
}

BOOST_PYTHON_MODULE(TestClass)
{
def("TestFunc",TestFunc);
}
It compiles and I can use it without a problem. However, when I try to
wrap a class with code like this:

class TestClass
{
public:
TestClass() {};
~TestClass() {};
string TestFunction(){return "Hello World";};
};

BOOST_PYTHON_MODULE(TestClass)
{
class_<TestClass>("TestClass")
.def("TestFunction",&TestClass.TestFunction)
;
}
I get the following error:
vc-C++
bin\PythonTest\TestClass.pyd\vc-8_0\debug\threading-multi\TestClass.obj
TestClass.cpp
TestClass.cpp(27) : error C2976: 'boost::python::class_' : too few
template arguments

c:\Development\Boost\boost_1_33_1\boost/python/def_visitor.hpp(14) :
see declaration of 'boost::python::class_'
TestClass.cpp(27) : error C2440: '<function-style-cast>' : cannot
convert from 'const char [10]' to 'boost::python::class_'
Source or target has incomplete type

I'm using Visual Studio 2005 Express Edition (I get the same error with
2003 Professional), and am using bJam to build the extension.

Does anyone have any idea what's causing this?
Aug 31 '06 #2
JDJMSon wrote:
I was wondering if someone here could help me with a problem I'm having
building Python extensions with the Boost.Python library.
Basically, if I have a wrapper class with something like this:

string TestFunc()
{
return "Hello World";
}

BOOST_PYTHON_MODULE(TestClass)
{
def("TestFunc",TestFunc);
}
It compiles and I can use it without a problem. However, when I try to
wrap a class with code like this:

class TestClass
{
public:
TestClass() {};
~TestClass() {};
string TestFunction(){return "Hello World";};
};

BOOST_PYTHON_MODULE(TestClass)
{
class_<TestClass>("TestClass")
.def("TestFunction",&TestClass.TestFunction)
;
}

Shouldn't that be:
..def("TestFunction",&TestClass::TestFunction)
;
Sep 1 '06 #3

Neal Becker wrote:
Shouldn't that be:
.def("TestFunction",&TestClass::TestFunction)
;

Yes, you're right, but I'm still getting the error. I'm using a
prebuilt python library, so later I'm going to rebuild python myself
and see if that helps, as has been suggested.
Thanks.

Sep 1 '06 #4
JDJMSon wrote:
>
Neal Becker wrote:
>Shouldn't that be:
.def("TestFunction",&TestClass::TestFunction)
;


Yes, you're right, but I'm still getting the error. I'm using a
prebuilt python library, so later I'm going to rebuild python myself
and see if that helps, as has been suggested.
Thanks.
I think you need an init. Usually looks like:

class_< c++ class ("python name", init<args..>())
..def ("python member", &class::member);

Sep 1 '06 #5

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

Similar topics

0
by: Li Daobing | last post by:
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> ...
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:...
0
by: Osiris | last post by:
My experiences with BOOST on Windows XP and Visual C++ 2005 I'm new to Python. I built software in more than ten other computer languages. I'm not sure if that is not a handicap, when reading...
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...
2
by: skip | last post by:
We encountered a situation today where it appeared that a Boost.Python-provided class didn't participate in Python's cyclic garbage collection. The wrapped C++ instance held a reference to a...
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...
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...
5
by: Stodge | last post by:
I've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of strings. Though I think it implements it using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.