Boost logo

Boost Users :

From: texrmex (texrmex_at_[hidden])
Date: 2002-11-04 18:27:52


First, I'm excited about the new work that's been done with Boost
Python v2. I can't wait to see if it's enough to overcome the
pitfalls that prevented me from getting past the evaluation stage
with v1.

I'm using VC7 IDE to build my project and link to python22.lib and
boost_python.lib (built with VC7 command line tools using bjam). I'm
attempting to extend and embed in my existing project, so I'm not
building a dll, but and exe. First of all, can I do this? When it
links it says "Creating library ....lib and object ....exp", and
still creates an exe. If I don't include my test module (and thus
boost/python.hpp) I don't get this message. I'm assuming that by
defining a module, boost defines exports and the linker then creates
the lib and exp, since there were exports? Although I've built dlls
before, I really don't know the inner workings of the process.

The following is a brief example of my module. At the bottom is a
simple test function that I'm calling just to test importing of the
module. When I call TestModule(), I get 2 memory leaks from the
module definition section, one from the class definition, and the
other from the method definition. If I remove these, I get no memory
leaks, and if I add more classes and methods, I get one 12 byte leak
per class and one 12 byte leak per method I add. I do not get a leak
from defining the top level function "greet".

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

namespace {

const char * greet() {
    return "Hello World";
}

class CSimple
{
public:
        bool Test() { return true; }
};

};

BOOST_PYTHON_MODULE(Test)
{
    def("greet", greet);

    class_<CSimple>("Simple")
        .def("Test", &CSimple::Test)
    ;
}

void TestModule()
{
    Py_Initialize();
    initTest();
    Py_Finalize();
}
///////////////////////////////////////////////////

In addition to the memory leaks, I get a number of compiler warnings,
similar to the following:

d:\Boost\boost\python\instance_holder.hpp(18) : warning C4275: non
dll-interface class 'boost::noncopyable' used as base for dll-
interface struct 'boost::python::instance_holder'
        d:\Boost\boost\utility.hpp(50) : see declaration
of 'boost::noncopyable'
        d:\Boost\boost\python\instance_holder.hpp(17) : see
declaration of 'boost::python::instance_holder'

*and*

d:\Boost\boost\python\detail\exception_handler.hpp(34) : warning
C4251: 'boost::python::detail::exception_handler::m_impl' :
class 'boost::function2<R,T0,T1,Policy,Mixin,Allocator>' needs to
have dll-interface to be used by clients of
struct 'boost::python::detail::exception_handler'
        with
        [
            R=bool,
            T0=const boost::python::detail::exception_handler &,
            T1=const
boost::function0<void,boost::empty_function_policy,boost::empty_functi
on_mixin,int> &,
            Policy=boost::empty_function_policy,
            Mixin=boost::empty_function_mixin,
            Allocator=int
        ]

I was wondering if my project is not set up properly, and if these
warnings might have something to do with the memory leaks.

In v1 there was a vc project you could use for building boost
python. This works well if you are planning on linking to a vc built
project, since you can make sure your settings, paths and libs are
consistent between the boost python lib and your project. I
currently have 3 different sets of build tools (yes, 3 compilers) on
this box, with several different versions of standard and other
libraries, so making sure I have control of the paths and settings
used is very important.

This is one reason I'm weary of the jam environment. It's yet
another build environment, one that I'm not familiar with, and one
that I'm not going to be using with any other projects except to
build boost python. So a question would be: how easy would it be for
me to set up a VC project for building boost python? Has this
already been done? Or am I barking up the wrong tree?

Thanks in advance,
-Tex


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