Archived

This topic is now archived and is closed to further replies.

stodge

Error compiling test program with boost::python

Recommended Posts

stodge    144
I''m trying to compile a simple example with boost:ython using g++ as opposed to using bjam. When I compile I get:
var.cpp:14: `init'' was not declared in this scope
var.cpp:14: parse error before `>'' token
var.cpp:15: ISO C++ forbids declaration of `class_'' with no type
var.cpp:15: template-id `class_<Var>'' in declaration of primary template
var.cpp:16:44: warning: no newline at end of file
My source code is:
var.cpp:14: `init'' was not declared in this scope
var.cpp:14: parse error before `>'' token
var.cpp:15: ISO C++ forbids declaration of `class_'' with no type
var.cpp:15: template-id `class_<Var>'' in declaration of primary template
var.cpp:16:44: warning: no newline at end of file
So I''m assuming that I haven''t included a certain header file, but which one is it? Any help appreciated. Thanks

Share this post


Link to post
Share on other sites
stodge    144
Oh no! I didn''t notice that! lol

I just re-installed Linux, so let me see if I can restore the source.

Share this post


Link to post
Share on other sites
stodge    144
Here you go! lol


#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;

#include <string>

class Var
{
Var(std::string name) : name(name), value() {}
std::string const name;
float value;
};

class_<Var>("Var", init<std::string>())
.def_readonly("name", &Var::name)
.def_readwrite("value", &Var::value);

Share this post


Link to post
Share on other sites
Fruny    1658
Ok, here''s the simple answer : all you have to include is boost/python.hpp. The headers in boost/python/ are implementation details.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
c t o a n    163
Ok, I realize this is a bit old, but let me just point out something...

BOOST_PYTHON_MODULE(some_name_here)
{
// NOW put your class defs here
class_(...)
...
;
}



Chris Pergrossi
< ctoan >
My Realm

Share this post


Link to post
Share on other sites