Boost logo

Boost Users :

Subject: [Boost-users] boost.python class constructor error
From: hitesh dhiman (hitesh.dhiman.1988_at_[hidden])
Date: 2010-03-11 21:26:03


Hi all,
I'm trying out boost.python to use c++ code in python.
My problem is this: In my c++ code, if i declare the class constructor in
the header file, and define it in the cpp file, bjam throws a LNK2019
unresolved symbol error. The problem does not occur if i define the
constructor in the header file itself.
My code is shown below:

*Test1.h:*
#include <windows.h>
//using namespace std;

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

*Test1.cpp:*
#include "Test1.h"

World::World() {};
World::~World() {};
int addition(int a, int b)
{
int z = a + b;
return z;
}

*Wrapper File*:
#include <boost/python.hpp>
#include "Test1.h"

BOOST_PYTHON_MODULE(hello)
{
    using namespace boost::python;
class_<World>("World")
        .def("greet", &World::greet)
        .def("set", &World::set)
    ;
}

Is this a bug? Or there's something wrong with my coding here?

-- 
Regards,
Hitesh Dhiman
Electrical Engineering
National University of Singapore


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net