[C++-sig] "extension class wrapper for base class has not been created yet" error message on Linux for a project that works fine on Windows

Renato Araujo renatox at gmail.com
Wed Feb 4 18:08:54 CET 2009


Hi,

I got a error like this, I solved this fixing the order of the link
flags, libboost_python need be the first library.

BR



On Wed, Feb 4, 2009 at 1:46 PM, Andras Pap <andras.pap at coventor.com> wrote:
> I am creating a base class "Base::Foo" in Foo.dll(so) and expose it in the
> FooWrapper.pyd(so) module. Class "Derived::Bar" derives from Base::Foo and
> is in the Bar.dll(so) and exposed in the BarWrapper.pyd(so) module.
>
> On Windows the following works fine:
> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import FooWrapper
>>>> import BarWrapper
>>>> foo = FooWrapper.Foo()
>>>> bar = BarWrapper.Bar()
>>>> foo.sayHello()
> Hi I am Foo!
>>>> bar.sayHello()
> Hi I am Bar!
>>>>
>
> On Linux I get the:
> RuntimeError: extension class wrapper for base class Base::Foo has not been
> created yet error:
> Python 2.4.2 (#1, Jul  2 2008, 10:27:50)
> [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import FooWrapper
>>>> import BarWrapper
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> RuntimeError: extension class wrapper for base class Base::Foo has not been
> created yet
>>>>
>
> Instantiating "foo" before trying to import BarWrapper does not help:
> Python 2.4.2 (#1, Jul  2 2008, 10:27:50)
> [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-59)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import FooWrapper
>>>> foo = FooWrapper.Foo()
>>>> foo.sayHello()
> Hi I am Foo!
>>>> import BarWrapper
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> RuntimeError: extension class wrapper for base class Base::Foo has not been
> created yet
>>>>
>
> I am hoping that I am missing a simple step, can anyone help what it may be?
>
>
> Here are: Foo.cpp/h, FooWrapper.cpp Bar.cpp/h and BarWrapper.cpp:
> foo.h:
> #ifndef BASE_FOO_H
> #define BASE_FOO_H
>
> namespace Base
> {
>
>  class TEST_BASE Foo
>  {
>
>  public:
>   /// ctor
>   Foo();
>
>   /// dtor
>   virtual ~Foo();
>
>   virtual void sayHello();
>  };
>
> } // namespace Base
>
> #endif //BASE_FOO_H
>
> foo.cpp:
> #include <iostream>
> #include "Foo.h"
>
> using namespace Base;
>
> Foo::Foo()
> {
> };
>
> Foo::~Foo()
> {
> };
>
> void Foo::sayHello()
> {
>  std::cout << "Hi I am Foo!" << std:: endl;
> }
>
> FooWrapper.h:
> #include <vector>
> #include <string>
>
> #include <boost/python/class.hpp>
> #include <boost/python/module.hpp>
>
> #include <Foo.h>
>
> BOOST_PYTHON_MODULE(FooWrapper)
> {
>  using namespace std;
>  using namespace boost::python;
>  using namespace Base;
>
>  // Python wrapper for MaterialDocument
>  class_<Foo>("Foo")
>   .def("sayHello", &Foo::sayHello)
>   ;
> }
>
> Bar.h:
> #ifndef DERIVED_BAR_H
> #define DERIVED_BAR_H
>
> #include "Foo.h"
>
> namespace Derived
> {
>
>  class TEST_DERIVED Bar : public Base::Foo
>  {
>
>  public:
>   /// ctor
>   Bar();
>
>   /// dtor
>   virtual ~Bar();
>
>   virtual void sayHello();
>  };
>
> } // namespace Derived
>
> #endif //DERIVED_BAR_H
>
> Bar.cpp
> #include <iostream>
> #include "Bar.h"
>
> using namespace Derived;
>
> Bar::Bar() : Base::Foo()
> {
> };
>
> Bar::~Bar()
> {
> };
>
> void Bar::sayHello()
> {
>  std::cout << "Hi I am Bar!" << std:: endl;
> }
>
> BarWrapper.cpp
> #include <vector>
> #include <string>
>
> #include <boost/python/class.hpp>
> #include <boost/python/module.hpp>
>
> #include <iostream>
> #include <string>
>
> #include <Bar.h>
>
> BOOST_PYTHON_MODULE(BarWrapper)
> {
>  using namespace std;
>  using namespace boost::python;
>  using namespace Derived;
>
>  // Python wrapper for MaterialDocument
>  class_<Bar, bases<Base::Foo> >("Bar")
>   .def("sayHello", &Bar::sayHello)
>   ;
> }
>
>
>
>
> --
> ----------------------------------------------
> Andras Pap               Ph:(617)497-6880x233
> Coventor, Inc.           Fax: (617)497-6882
> apap at coventor.com        Cell: (617)512-5768
> ----------------------------------------------
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
Renato Araujo Oliveira Filho


More information about the Cplusplus-sig mailing list