Jump to content
  • Advertisement

Archived

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

stodge

Error compiling test program with boost::python

This topic is 5488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!