Boost Python Issue

J

JDJMSon

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?
 
C

chris.felton

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.
 
N

Neal Becker

JDJMSon said:
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)
 
J

JDJMSon

Neal said:
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.
 
N

Neal Becker

JDJMSon said:
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);
 

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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top