Advertisement

Error compiling test program with boost::python

Started by July 08, 2003 10:53 AM
4 comments, last by stodge 21 years, 4 months ago
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
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
Advertisement
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
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
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
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"

This topic is closed to new replies.

Advertisement