[C++-sig] boost.python class constructor error

hitesh dhiman hitesh.dhiman.1988 at gmail.com
Fri Mar 12 05:01:39 CET 2010


hi Jim
Will it help if i post my jam-root file? Its included below:
import python ;

if ! [ python.configured ]
{
    ECHO "notice: no Python configured in user-config.jam" ;
    ECHO "notice: will use default configuration" ;
    using python ;
}

# Specify the path to the Boost project.  If you move this project,
# adjust this path to refer to the Boost root directory.
use-project boost
  : "C:/Program Files/boost/boost_1_42" ;

# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.
project
  : requirements <library>/boost/python//boost_python ;

# Declare the three extension modules.  You can specify multiple
# source files after the colon separated by spaces.
python-extension hello : TestWrap.cpp ;

# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{
    import testing ;
    testing.make-test run-pyd : $(sources) : : $(test-name) ;
}


>From what you said, its seems the Test1.cpp file needs to be listed under
the extension modules,  is it?
Its as if bjam is totally ignoring Test1.cpp. Any definition/declaration in
Test1.cpp file doesn't work.

On Fri, Mar 12, 2010 at 11:38 AM, Jim Bosch <talljimbo at gmail.com> wrote:

> On Fri, 2010-03-12 at 10:36 +0800, hitesh dhiman wrote:
> > This error occurs when i declare the class constructor in the c++
> > header file and the definition in the .cpp file. Bjam throws up a
> > LNK2019 error, unresolved symbol.
> > But if i declare the class constructor in the header file itself, the
> > code compiles.
> > Here's the code:
> >
> >
> > 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 it a compiler bug? I want to define the constructors in the cpp
> > file, and not the header file.
> > --
>
> I've never had any problems doing exactly that, and I can't say more
> about your particular situation without seeing your build system setup
> (which probably actually wouldn't help me, since I don't know much about
> bjam or Windows).
>
> Are you certain your source file is getting compiled into (or otherwise
> linked) to the module's shared library?
>
> Did you compile the source file with the same compiler flags as the
> wrapper file?  They probably don't have to be identical, but some may be
> important.
>
> My guess that it's not just the constructor; you aren't linking against
> anything in your non-wrapper cpp file.
>
>
> Jim
>
>
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
Regards,
Hitesh Dhiman
Electrical Engineering
National University of Singapore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100312/dbf518a7/attachment-0001.html>


More information about the Cplusplus-sig mailing list