[C++-sig] Compile error with tutorial

David Huebel davidhuebel at gmail.com
Tue Dec 13 06:25:15 CET 2005


I'm just getting started with Boost Python, using boost_1_32_0.  The
following code (which should look familiar) compiles and runs just

char const* greet()
   return "hello, world";

#include <string>

struct World

    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::string msg;

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

    def("greet", greet);
	.def("greet", &World::greet)
	.def("set", &World::set)

When I uncomment the two sections referring to World, I get the
following compile error:

...found 652 targets...
...updating 2 targets...
gcc-C++-action bin/tutorial/hello.so/gcc/debug/shared-linkable-true/hello.o
hello.cpp: In function `void init_module_hello()':
hello.cpp:26: wrong number of template arguments (1, should be 4)
/home/cdt/lib/boost_1_32_0/boost/python/def_visitor.hpp:14: provided for `
   template<class T, class X1, class X2, class X3> struct boost::python::class_

    set -e
    "g++"   -c -Wall -ftemplate-depth-255  -DBOOST_PYTHON_DYNAMIC_LIB 
-g -O0 -fno-inline -fPIC   -I"bin/tutorial"   -I
"/usr/include/python2.2" -I "/home/cdt/lib/boost_1_32_0"  -o
    "/usr/bin/objcopy" --set-section-flags .debug_str=contents,debug

...failed gcc-C++-action
...removing bin/tutorial/hello.so/gcc/debug/shared-linkable-true/hello.o
...skipped <@tutorial/hello.so/gcc/debug/shared-linkable-true>hello.so
for lack of <@tutorial/hello.so/gcc/debug/shared-linkable-true>hello.o...
...failed updating 1 target...
...skipped 1 target...

Line 26 is the line containing class_.  I'm using gcc 3.2.3 and python
2.2.3 on Linux.  What am I doing wrong?

As an aside, I found it very difficult to figure out how to build
extensions outside the Boost build tree and then how to build an
extension based on a separately compiled object.  My problem was that
I started with no knowledge of Jam and no idea how much Jam I should
learn before tackling Boost Python.  I think it would be a good
addition to the tutorial to recommend learning the Jam syntax and the
basic Jambase rules for linking C++ projects before attempting to
deviate from the tutorial build setup.

David Huebel

More information about the Cplusplus-sig mailing list