Skip to main content
GameDev.net gamedev.net
🔒 Locked

Error compiling test program with boost::python

Started by stodge Jul 8, 2003 at 10:53 AM 4 replies 1.2k views
Original Post
stodge
stodge
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
---------------------http://www.stodge.net
Fruny
Fruny
You posted the error messages twice, seeing your code would be more helpful


[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
stodge
stodge
Oh no! I didn''t notice that! lol

I just re-installed Linux, so let me see if I can restore the source.
---------------------http://www.stodge.net
stodge
stodge
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);
---------------------http://www.stodge.net
Fruny
Fruny
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
c t o a n
c t o a n
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
Chris PergrossiMy Realm | "Good Morning, Dave"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.