problems with SWIG and C++

Cesar Lopez clopez at abo.fi
Wed Dec 15 08:30:32 EST 1999


I´m a beginner with python and SWIG, I want to include some C++ classes
and methods definitions into python interpreter so that I define the
file derive.i in this way:

%module derived
%import device.h
class Led : public Device {
public:
        // constructor
        Led(int id);                            // Led Identifier

        // destructor
        ~Led();
        // members function
        int Setup(int state); // state = 1 --> ON ; state = 0 --> OFF

};


Here is my device.h file:

//device.h
// This module implements the main class device that will used by the
others devices definit
ions
//

class Device{   // Base class of Devices system
public:
        // variables
        int Id;                                 // Device Identifier
        char *Comments;                         // Special things about
the device

        // constructors
        Device(int id);                                 // All devices
needs an Id number

        // virtual destructor!
        virtual ~Device();

        virtual int Setup();  // return 0 if all goes well or error
number in other case

};


Then when I run SWIG there is no problem:

bash-2.02$ swig -python -c++  derived.i
Generating wrappers for Python

The problem is when I try to compile it:

bash-2.02$ sh-hms-g++ -c  led.c++ derived_wrap.c
-I/usr/include/python1.5
derived_wrap.c: In function `void * SwigLedToDevice(void *)':
derived_wrap.c:556: `Led' undeclared (first use this function)
derived_wrap.c:556: (Each undeclared identifier is reported only once
derived_wrap.c:556: for each function it appears in.)


I´ve try to put in my derived.i file this lines: %include device.cpp
and %include led.cpp  even I try to combine them with %import
device.cpp  and %import led.cpp   but doesn´t work.

So I think that I need to expecify something more in my derived.i but I
don´t know How.

If you know how to solve this problem, please e-mail me.

Perhaps I must to use old C and no c++ classes.!!




More information about the Python-list mailing list