[C++-sig] Problems with cross module problems with current boost CVS, Python 2.3, OS 10.3.9, and gcc 3.3

Joseph Winston josephwinston at mac.com
Fri Jul 22 05:10:52 CEST 2005


I built boost from cvs as follows:

$  bjam "-sTOOLS=darwin"

And then installed it.

But I'm having problems with the following simple program:

--- Base.hpp ---
#include <iostream>

class Base 
{
public:
   Base() 
   { 
      std::cerr << "Base()" << std::endl;
   }
   virtual ~Base() 
   { 
      std::cerr << "~Base()" << std::endl;
   }
   virtual void printMessage() const
   { 
      std::cerr << "Base instance @ " << this << std::endl;
   }
};

--- Base.cpp ---
#include "Base.hpp"
#include <boost/python.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(Base)
{
   class_<Base>("Base", init<>())
      .def("printMessage", &Base::printMessage)
      ;
}

--- Derived.hpp ---
#include <iostream>
#include "Base.hpp"

class Derived: public Base
{
public:
   Derived(): Base()
   { 
      std::cerr << "Derived()" << std::endl;
   }
   virtual ~Derived()
   { 
      std::cerr << "~Derived()" << std::endl;
   }
   virtual void printMessage() const
   { 
      std::cerr << "Derived instance @ " << this << std::endl;
   }
};

--- Derived.cpp ---
#include "Derived.hpp"
#include <boost/python.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(Derived)
{
   class_<Derived, bases<Base> >("Derived", init<>());
}

The two programs were compiled using:

$ g++ -fPIC -no-cpp-precomp -finline-functions -Wno-long-double
-F/System/Library/Frameworks -ftemplate-depth-256 -DBOOST_PYTHON_DYNAMIC_LIB
-fPIC 
-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3
-I/Users/josephwinston/src/OpenAvionics/powerpc-apple-darwin7.9.0/include -c
-o Base.os Base.cpp
$ g++ -fPIC -no-cpp-precomp -finline-functions -Wno-long-double
-F/System/Library/Frameworks -ftemplate-depth-256 -DBOOST_PYTHON_DYNAMIC_LIB
-fPIC 
-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3
-I/Users/josephwinston/src/OpenAvionics/powerpc-apple-darwin7.9.0/include -c
-o Derived.os Derived.cpp

And linked into two modules:

$ g++ -bundle -flat_namespace -undefined suppress -o Base.so Base.os -lm
-lstdc++ -ldl 
-L/Users/josephwinston/src/OpenAvionics/powerpc-apple-darwin7.9.0/lib
-lboost_python
$ g++ -bundle -flat_namespace -undefined suppress -o Derived.so Derived.os
-lm -lstdc++ -ldl 
-L/Users/josephwinston/src/OpenAvionics/powerpc-apple-darwin7.9.0/lib
-lboost_python

Loaded into python:

$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Base
>>> import Derived
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: extension class wrapper for base class Base has not been
created yet

Obviously, I'm either not building boost correctly or I'm not linking
correctly.  Does anybody see what I'm doing wrong?

Thanks
 






More information about the Cplusplus-sig mailing list