Hi I am trying the swig python extension, in c++, example - on an Mit page
My header is - shapes.h
#include <iostream>
class Shape
{
public:
Shape()
{
nshapes++;
}
~Shape()
{
nshapes--;
}
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area();
virtual double perimeter();
};
The corresponding interface file is - shapesModule.i
%module shapes
%{
#include "shapes.h"
%}
/* Let's just grab the original header file here */
%include "shapes.h"
I first ran swig command - swig -c++ -python shapesModule.i
This generated the following 2 files - shapesModule_wrap.cxx shapes.py
Then I ran the g++ compiler - g++ shapes.h shapesModule_wrap.cxx -I/usr/include/python2.7
But I get a lot of error which I cannot understand -
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 21 has invalid symbol index 22
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/ccfPRfYo.o: In function `SWIG_Python_str_AsChar(_object*)':
shapesModule_wrap.cxx:(.text+0x8ad): undefined reference to `PyString_AsString'
/tmp/ccfPRfYo.o: In function `SWIG_Python_str_FromChar(char const*)':
shapesModule_wrap.cxx:(.text+0x8c0): undefined reference to `PyString_FromString'
/tmp/ccfPRfYo.o: In function `SWIG_Python_ErrorType(int)':
shapesModule_wrap.cxx:(.text+0x8e8): undefined reference to `PyExc_MemoryError'
shapesModule_wrap.cxx:(.text+0x8f2): undefined reference to `PyExc_IOError'
shapesModule_wrap.cxx:(.text+0x8fc): undefined reference to `PyExc_RuntimeError'
shapesModule_wrap.cxx:(.text+0x906): undefined reference to `PyExc_IndexError'
shapesModule_wrap.cxx:(.text+0x910): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0x91a): undefined reference to `PyExc_ZeroDivisionError'
shapesModule_wrap.cxx:(.text+0x924): undefined reference to `PyExc_OverflowError'
shapesModule_wrap.cxx:(.text+0x92e): undefined reference to `PyExc_SyntaxError'
shapesModule_wrap.cxx:(.text+0x938): undefined reference to `PyExc_ValueError'
shapesModule_wrap.cxx:(.text+0x942): undefined reference to `PyExc_SystemError'
shapesModule_wrap.cxx:(.text+0x94c): undefined reference to `PyExc_AttributeError'
shapesModule_wrap.cxx:(.text+0x956): undefined reference to `PyExc_RuntimeError'
/tmp/ccfPRfYo.o: In function `SWIG_Python_AddErrorMsg(char const*)':
shapesModule_wrap.cxx:(.text+0x97e): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x9a0): undefined reference to `PyErr_Fetch'
shapesModule_wrap.cxx:(.text+0x9b6): undefined reference to `PyObject_Str'
shapesModule_wrap.cxx:(.text+0x9be): undefined reference to `PyErr_Clear'
shapesModule_wrap.cxx:(.text+0x9fe): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0xa59): undefined reference to `PyExc_RuntimeError'
shapesModule_wrap.cxx:(.text+0xa68): undefined reference to `PyErr_SetString'
/tmp/ccfPRfYo.o: In function `SWIG_Python_SetErrorObj(_object*, _object*)':
shapesModule_wrap.cxx:(.text+0xa8c): undefined reference to `PyErr_SetObject'
/tmp/ccfPRfYo.o: In function `SWIG_Python_SetErrorMsg(_object*, char const*)':
shapesModule_wrap.cxx:(.text+0xad2): undefined reference to `PyErr_SetString'
/tmp/ccfPRfYo.o: In function `SWIG_Python_SetConstant(_object*, char const*, _object*)':
shapesModule_wrap.cxx:(.text+0xaf3): undefined reference to `PyDict_SetItemString'
/tmp/ccfPRfYo.o: In function `SWIG_Python_AppendOutput(_object*, _object*)':
shapesModule_wrap.cxx:(.text+0xb3f): undefined reference to `_Py_NoneStruct'
shapesModule_wrap.cxx:(.text+0xb99): undefined reference to `PyList_New'
shapesModule_wrap.cxx:(.text+0xbb6): undefined reference to `PyList_SetItem'
shapesModule_wrap.cxx:(.text+0xbc8): undefined reference to `PyList_Append'
/tmp/ccfPRfYo.o: In function `SWIG_Python_UnpackTuple(_object*, char const*, int, int, _object**)':
shapesModule_wrap.cxx:(.text+0xc37): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0xc59): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0xcbb): undefined reference to `PyExc_SystemError'
shapesModule_wrap.cxx:(.text+0xccb): undefined reference to `PyErr_SetString'
shapesModule_wrap.cxx:(.text+0xcfa): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0xd20): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0xd49): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0xd6f): undefined reference to `PyErr_Format'
/tmp/ccfPRfYo.o: In function `SWIG_Py_Void':
shapesModule_wrap.cxx:(.text+0xdd0): undefined reference to `_Py_NoneStruct'
/tmp/ccfPRfYo.o: In function `SwigPyClientData_New':
shapesModule_wrap.cxx:(.text+0xe26): undefined reference to `PyClass_Type'
shapesModule_wrap.cxx:(.text+0xe5f): undefined reference to `PyObject_GetAttrString'
shapesModule_wrap.cxx:(.text+0xe88): undefined reference to `PyTuple_New'
shapesModule_wrap.cxx:(.text+0xeab): undefined reference to `PyTuple_SetItem'
shapesModule_wrap.cxx:(.text+0xed8): undefined reference to `PyObject_GetAttrString'
shapesModule_wrap.cxx:(.text+0xee3): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0xef1): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SwigPyObject_long':
shapesModule_wrap.cxx:(.text+0x1021): undefined reference to `PyLong_FromVoidPtr'
/tmp/ccfPRfYo.o: In function `SwigPyObject_format':
shapesModule_wrap.cxx:(.text+0x103c): undefined reference to `PyTuple_New'
shapesModule_wrap.cxx:(.text+0x106b): undefined reference to `PyTuple_SetItem'
shapesModule_wrap.cxx:(.text+0x109e): undefined reference to `PyString_Format'
/tmp/ccfPRfYo.o: In function `SwigPyObject_repr':
shapesModule_wrap.cxx:(.text+0x1174): undefined reference to `PyString_FromFormat'
shapesModule_wrap.cxx:(.text+0x11a4): undefined reference to `PyString_ConcatAndDel'
/tmp/ccfPRfYo.o: In function `SwigPyObject_richcompare':
shapesModule_wrap.cxx:(.text+0x11fd): undefined reference to `_Py_NotImplementedStruct'
shapesModule_wrap.cxx:(.text+0x1205): undefined reference to `_Py_NotImplementedStruct'
shapesModule_wrap.cxx:(.text+0x120a): undefined reference to `_Py_NotImplementedStruct'
shapesModule_wrap.cxx:(.text+0x1244): undefined reference to `PyBool_FromLong'
/tmp/ccfPRfYo.o: In function `SwigPyObject_dealloc':
shapesModule_wrap.cxx:(.text+0x13ab): undefined reference to `PyObject_CallFunctionObjArgs'
shapesModule_wrap.cxx:(.text+0x14ab): undefined reference to `PyObject_Free'
/tmp/ccfPRfYo.o: In function `SwigPyObject_own':
shapesModule_wrap.cxx:(.text+0x1594): undefined reference to `PyArg_UnpackTuple'
shapesModule_wrap.cxx:(.text+0x15b8): undefined reference to `PyBool_FromLong'
shapesModule_wrap.cxx:(.text+0x15cd): undefined reference to `PyObject_IsTrue'
/tmp/ccfPRfYo.o: In function `SwigPyObject_TypeOnce':
shapesModule_wrap.cxx:(.text+0x164e): undefined reference to `PyType_Ready'
/tmp/ccfPRfYo.o: In function `SwigPyObject_New':
shapesModule_wrap.cxx:(.text+0x168a): undefined reference to `PyObject_Malloc'
shapesModule_wrap.cxx:(.text+0x1696): undefined reference to `PyObject_Init'
/tmp/ccfPRfYo.o: In function `SwigPyPacked_repr':
shapesModule_wrap.cxx:(.text+0x1866): undefined reference to `PyString_FromFormat'
shapesModule_wrap.cxx:(.text+0x1883): undefined reference to `PyString_FromFormat'
/tmp/ccfPRfYo.o: In function `SwigPyPacked_str':
shapesModule_wrap.cxx:(.text+0x1919): undefined reference to `PyString_FromFormat'
/tmp/ccfPRfYo.o: In function `SwigPyPacked_dealloc':
shapesModule_wrap.cxx:(.text+0x1aa2): undefined reference to `PyObject_Free'
/tmp/ccfPRfYo.o: In function `SwigPyPacked_TypeOnce':
shapesModule_wrap.cxx:(.text+0x1b2d): undefined reference to `PyObject_GenericGetAttr'
shapesModule_wrap.cxx:(.text+0x1b6f): undefined reference to `PyType_Ready'
/tmp/ccfPRfYo.o: In function `SwigPyPacked_New':
shapesModule_wrap.cxx:(.text+0x1bab): undefined reference to `PyObject_Malloc'
shapesModule_wrap.cxx:(.text+0x1bb7): undefined reference to `PyObject_Init'
shapesModule_wrap.cxx:(.text+0x1c15): undefined reference to `PyObject_Free'
/tmp/ccfPRfYo.o: In function `SWIG_Python_GetSwigThis':
shapesModule_wrap.cxx:(.text+0x1cea): undefined reference to `PyInstance_Type'
shapesModule_wrap.cxx:(.text+0x1d00): undefined reference to `_PyInstance_Lookup'
shapesModule_wrap.cxx:(.text+0x1d13): undefined reference to `_PyObject_GetDictPtr'
shapesModule_wrap.cxx:(.text+0x1d3e): undefined reference to `PyDict_GetItem'
shapesModule_wrap.cxx:(.text+0x1d58): undefined reference to `_PyWeakref_ProxyType'
shapesModule_wrap.cxx:(.text+0x1d65): undefined reference to `_PyWeakref_CallableProxyType'
shapesModule_wrap.cxx:(.text+0x1d80): undefined reference to `_Py_NoneStruct'
shapesModule_wrap.cxx:(.text+0x1db4): undefined reference to `PyObject_GetAttr'
shapesModule_wrap.cxx:(.text+0x1df0): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x1dfe): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_Python_ConvertPtrAndOwn':
shapesModule_wrap.cxx:(.text+0x1ea8): undefined reference to `_Py_NoneStruct'
shapesModule_wrap.cxx:(.text+0x208e): undefined reference to `PyObject_CallFunctionObjArgs'
shapesModule_wrap.cxx:(.text+0x20a0): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x20ae): undefined reference to `PyErr_Clear'
shapesModule_wrap.cxx:(.text+0x216c): undefined reference to `_Py_NoneStruct'
shapesModule_wrap.cxx:(.text+0x2182): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2190): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_Python_ConvertFunctionPtr':
shapesModule_wrap.cxx:(.text+0x21ad): undefined reference to `PyCFunction_Type'
/tmp/ccfPRfYo.o: In function `SWIG_Python_NewShadowInstance':
shapesModule_wrap.cxx:(.text+0x2381): undefined reference to `PyObject_Call'
shapesModule_wrap.cxx:(.text+0x2395): undefined reference to `_PyObject_GetDictPtr'
shapesModule_wrap.cxx:(.text+0x23b1): undefined reference to `PyDict_New'
shapesModule_wrap.cxx:(.text+0x23d7): undefined reference to `PyDict_SetItem'
shapesModule_wrap.cxx:(.text+0x23de): undefined reference to `PyDict_New'
shapesModule_wrap.cxx:(.text+0x2402): undefined reference to `PyDict_SetItem'
shapesModule_wrap.cxx:(.text+0x2417): undefined reference to `PyInstance_NewRaw'
/tmp/ccfPRfYo.o: In function `SWIG_Python_SetSwigThis':
shapesModule_wrap.cxx:(.text+0x245c): undefined reference to `_PyObject_GetDictPtr'
shapesModule_wrap.cxx:(.text+0x2478): undefined reference to `PyDict_New'
shapesModule_wrap.cxx:(.text+0x249e): undefined reference to `PyDict_SetItem'
shapesModule_wrap.cxx:(.text+0x24b3): undefined reference to `PyObject_GetAttrString'
shapesModule_wrap.cxx:(.text+0x24d1): undefined reference to `PyDict_SetItem'
/tmp/ccfPRfYo.o: In function `SWIG_Python_NewPointerObj':
shapesModule_wrap.cxx:(.text+0x263d): undefined reference to `_PyObject_New'
/tmp/ccfPRfYo.o: In function `SWIG_Python_GetModule':
shapesModule_wrap.cxx:(.text+0x277a): undefined reference to `PyCapsule_Import'
shapesModule_wrap.cxx:(.text+0x2784): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2792): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_Python_DestroyModule':
shapesModule_wrap.cxx:(.text+0x27bd): undefined reference to `PyCapsule_GetPointer'
/tmp/ccfPRfYo.o: In function `SWIG_Python_SetModule':
shapesModule_wrap.cxx:(.text+0x2886): undefined reference to `Py_InitModule4'
shapesModule_wrap.cxx:(.text+0x28a4): undefined reference to `PyCapsule_New'
shapesModule_wrap.cxx:(.text+0x28cd): undefined reference to `PyModule_AddObject'
/tmp/ccfPRfYo.o: In function `SWIG_Python_TypeCache':
shapesModule_wrap.cxx:(.text+0x2936): undefined reference to `PyDict_New'
/tmp/ccfPRfYo.o: In function `SWIG_Python_TypeQuery':
shapesModule_wrap.cxx:(.text+0x29a1): undefined reference to `PyDict_GetItem'
shapesModule_wrap.cxx:(.text+0x29bd): undefined reference to `PyCapsule_GetPointer'
shapesModule_wrap.cxx:(.text+0x2a11): undefined reference to `PyCapsule_New'
shapesModule_wrap.cxx:(.text+0x2a2d): undefined reference to `PyDict_SetItem'
/tmp/ccfPRfYo.o: In function `SWIG_Python_AddErrMesg':
shapesModule_wrap.cxx:(.text+0x2a95): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2ad0): undefined reference to `PyErr_Fetch'
shapesModule_wrap.cxx:(.text+0x2ae6): undefined reference to `PyObject_Str'
shapesModule_wrap.cxx:(.text+0x2aff): undefined reference to `PyErr_Clear'
shapesModule_wrap.cxx:(.text+0x2b34): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0x2b65): undefined reference to `PyErr_Format'
/tmp/ccfPRfYo.o: In function `SWIG_Python_ArgFail':
shapesModule_wrap.cxx:(.text+0x2bba): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2be8): undefined reference to `PyOS_snprintf'
/tmp/ccfPRfYo.o: In function `SWIG_Python_TypeError':
shapesModule_wrap.cxx:(.text+0x2c56): undefined reference to `PyObject_Str'
shapesModule_wrap.cxx:(.text+0x2c7f): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0x2ca4): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0x2cab): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0x2cc9): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0x2d04): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0x2d1b): undefined reference to `PyErr_Format'
shapesModule_wrap.cxx:(.text+0x2d22): undefined reference to `PyExc_TypeError'
shapesModule_wrap.cxx:(.text+0x2d32): undefined reference to `PyErr_Format'
/tmp/ccfPRfYo.o: In function `SWIG_Python_MustGetPtr':
shapesModule_wrap.cxx:(.text+0x2d71): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_AsVal_double(_object*, double*)':
shapesModule_wrap.cxx:(.text+0x2d8e): undefined reference to `PyFloat_Type'
shapesModule_wrap.cxx:(.text+0x2d9e): undefined reference to `PyFloat_Type'
shapesModule_wrap.cxx:(.text+0x2da6): undefined reference to `PyType_IsSubtype'
shapesModule_wrap.cxx:(.text+0x2dcb): undefined reference to `PyFloat_AsDouble'
shapesModule_wrap.cxx:(.text+0x2dfd): undefined reference to `PyInt_AsLong'
shapesModule_wrap.cxx:(.text+0x2e2c): undefined reference to `PyLong_AsDouble'
shapesModule_wrap.cxx:(.text+0x2e34): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2e57): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_AsVal_long(_object*, long*)':
shapesModule_wrap.cxx:(.text+0x2e85): undefined reference to `PyInt_AsLong'
shapesModule_wrap.cxx:(.text+0x2eae): undefined reference to `PyLong_AsLong'
shapesModule_wrap.cxx:(.text+0x2eb6): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x2ed9): undefined reference to `PyErr_Clear'
/tmp/ccfPRfYo.o: In function `SWIG_From_int(int)':
shapesModule_wrap.cxx:(.text+0x2f25): undefined reference to `PyInt_FromLong'
/tmp/ccfPRfYo.o: In function `_wrap_delete_Shape':
shapesModule_wrap.cxx:(.text+0x2f6b): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_x_set':
shapesModule_wrap.cxx:(.text+0x3065): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_x_get':
shapesModule_wrap.cxx:(.text+0x3189): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3210): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_y_set':
shapesModule_wrap.cxx:(.text+0x3277): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_y_get':
shapesModule_wrap.cxx:(.text+0x339b): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3422): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_move':
shapesModule_wrap.cxx:(.text+0x349e): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x35c3): undefined reference to `Shape::move(double, double)'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_area':
shapesModule_wrap.cxx:(.text+0x361a): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x36aa): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_perimeter':
shapesModule_wrap.cxx:(.text+0x36fc): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x378f): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `Swig_var_Shape_nshapes_set':
shapesModule_wrap.cxx:(.text+0x37f6): undefined reference to `Shape::nshapes'
/tmp/ccfPRfYo.o: In function `Swig_var_Shape_nshapes_get':
shapesModule_wrap.cxx:(.text+0x380f): undefined reference to `Shape::nshapes'
/tmp/ccfPRfYo.o: In function `_wrap_Shape_nshapes_set':
shapesModule_wrap.cxx:(.text+0x384c): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `Shape_swigregister':
shapesModule_wrap.cxx:(.text+0x389e): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_new_Circle':
shapesModule_wrap.cxx:(.text+0x390f): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_Circle_area':
shapesModule_wrap.cxx:(.text+0x3a02): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3a92): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_Circle_perimeter':
shapesModule_wrap.cxx:(.text+0x3ae4): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3b77): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_delete_Circle':
shapesModule_wrap.cxx:(.text+0x3bca): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `Circle_swigregister':
shapesModule_wrap.cxx:(.text+0x3c8c): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_new_Square':
shapesModule_wrap.cxx:(.text+0x3cfd): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `_wrap_Square_area':
shapesModule_wrap.cxx:(.text+0x3df0): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3e80): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_Square_perimeter':
shapesModule_wrap.cxx:(.text+0x3ed2): undefined reference to `PyArg_ParseTuple'
shapesModule_wrap.cxx:(.text+0x3f65): undefined reference to `PyFloat_FromDouble'
/tmp/ccfPRfYo.o: In function `_wrap_delete_Square':
shapesModule_wrap.cxx:(.text+0x3fb8): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `Square_swigregister':
shapesModule_wrap.cxx:(.text+0x407a): undefined reference to `PyArg_ParseTuple'
/tmp/ccfPRfYo.o: In function `swig_varlink_repr':
shapesModule_wrap.cxx:(.text+0x43f8): undefined reference to `PyString_FromString'
/tmp/ccfPRfYo.o: In function `swig_varlink_str':
shapesModule_wrap.cxx:(.text+0x440c): undefined reference to `PyString_FromString'
shapesModule_wrap.cxx:(.text+0x4427): undefined reference to `PyString_FromString'
shapesModule_wrap.cxx:(.text+0x4436): undefined reference to `PyString_ConcatAndDel'
shapesModule_wrap.cxx:(.text+0x444c): undefined reference to `PyString_FromString'
shapesModule_wrap.cxx:(.text+0x445b): undefined reference to `PyString_ConcatAndDel'
shapesModule_wrap.cxx:(.text+0x4476): undefined reference to `PyString_FromString'
shapesModule_wrap.cxx:(.text+0x4485): undefined reference to `PyString_ConcatAndDel'
/tmp/ccfPRfYo.o: In function `swig_varlink_getattr':
shapesModule_wrap.cxx:(.text+0x45b3): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x45cc): undefined reference to `PyExc_NameError'
shapesModule_wrap.cxx:(.text+0x45dc): undefined reference to `PyErr_SetString'
/tmp/ccfPRfYo.o: In function `swig_varlink_setattr':
shapesModule_wrap.cxx:(.text+0x463e): undefined reference to `PyErr_Occurred'
shapesModule_wrap.cxx:(.text+0x4657): undefined reference to `PyExc_NameError'
shapesModule_wrap.cxx:(.text+0x4667): undefined reference to `PyErr_SetString'
/tmp/ccfPRfYo.o: In function `swig_varlink_type':
shapesModule_wrap.cxx:(.text+0x472d): undefined reference to `PyType_Ready'
/tmp/ccfPRfYo.o: In function `SWIG_Python_newvarlink':
shapesModule_wrap.cxx:(.text+0x4769): undefined reference to `PyObject_Malloc'
shapesModule_wrap.cxx:(.text+0x4775): undefined reference to `PyObject_Init'
/tmp/ccfPRfYo.o: In function `SWIG_Python_InstallConstants':
shapesModule_wrap.cxx:(.text+0x496b): undefined reference to `PyDict_SetItemString'
/tmp/ccfPRfYo.o: In function `init_shapes':
shapesModule_wrap.cxx:(.text+0x4c5c): undefined reference to `Py_InitModule4'
shapesModule_wrap.cxx:(.text+0x4c6a): undefined reference to `PyModule_GetDict'
shapesModule_wrap.cxx:(.text+0x4cae): undefined reference to `PyDict_SetItemString'
/tmp/ccfPRfYo.o:(.rodata+0x2a8): undefined reference to `PyObject_GenericGetAttr'
/tmp/ccfPRfYo.o: In function `Shape::Shape()':
shapesModule_wrap.cxx:(.text._ZN5ShapeC2Ev[_ZN5ShapeC5Ev]+0xd): undefined reference to `Shape::nshapes'
shapesModule_wrap.cxx:(.text._ZN5ShapeC2Ev[_ZN5ShapeC5Ev]+0x15): undefined reference to `Shape::nshapes'
/tmp/ccfPRfYo.o: In function `Shape::~Shape()':
shapesModule_wrap.cxx:(.text._ZN5ShapeD2Ev[_ZN5ShapeD5Ev]+0xd): undefined reference to `Shape::nshapes'
shapesModule_wrap.cxx:(.text._ZN5ShapeD2Ev[_ZN5ShapeD5Ev]+0x15): undefined reference to `Shape::nshapes'
/tmp/ccfPRfYo.o: In function `Circle::Circle(double)':
shapesModule_wrap.cxx:(.text._ZN6CircleC2Ed[_ZN6CircleC5Ed]+0x22): undefined reference to `vtable for Circle'
/tmp/ccfPRfYo.o: In function `Square::Square(double)':
shapesModule_wrap.cxx:(.text._ZN6SquareC2Ed[_ZN6SquareC5Ed]+0x22): undefined reference to `vtable for Square'
/tmp/ccfPRfYo.o: In function `Circle::~Circle()':
shapesModule_wrap.cxx:(.text._ZN6CircleD2Ev[_ZN6CircleD5Ev]+0xb): undefined reference to `vtable for Circle'
/tmp/ccfPRfYo.o: In function `Square::~Square()':
shapesModule_wrap.cxx:(.text._ZN6SquareD2Ev[_ZN6SquareD5Ev]+0xb): undefined reference to `vtable for Square'
collect2: error: ld returned 1 exit status
I can't seem to understand what the problem is. I am new to swig so please provide some pointers. Plus any one know of any working examples with step by step tutorial that will also be appreciated.
update - the response from @m7thon fixed the compile errors. I am now getting error while importing the module into python -
Firstly, thanks for the response. that fixed my errors. :)
Bit I am getting the following error on import -
mishra14@mishra14-VirtualBox:~/sdn/cpp_class$ swig -c++ -python shapesModule.i
mishra14@mishra14-VirtualBox:~/sdn/cpp_class$ g++ -shared shapesModule_wrap.cxx $(python-config --includes) $(python-config --libs) -o _shapes.so
mishra14@mishra14-VirtualBox:~/sdn/cpp_class$ ls
shapes.h Shapes.h~ shapesModule.i shapesModule_wrap.cxx _shapes.so test.cpp~
shapes.h~ shapes.h.gch ShapesModule.i~ shapes.py test.cpp
mishra14@mishra14-VirtualBox:~/sdn/cpp_class$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:38)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shapes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "shapes.py", line 28, in <module>
_shapes = swig_import_helper()
File "shapes.py", line 24, in swig_import_helper
_mod = imp.load_module('_shapes', fp, pathname, description)
ImportError: ./_shapes.so: undefined symbol: _ZN5Shape4moveEdd
>>> quit()
I ran an nm on the _shapes.so file and i get the following for the symbol -
U _ZN5Shape4moveEdd
So i take it that IT IS undefined. Found about this - here but still not sure how to fix this.
You are apparently including the python headers, but not linking against the python library, so you are getting unresolved symbols.
You can run
python-config --cflags
python-config --ldflags
to find the required python include directories and libraries for your system, and add the output to your compilation line. Separating compilation and linking, you should be able to use:
g++ -fPIC -c shapes.cpp
g++ -fPIC -c shapesModule_wrap.cxx $(python-config --cflags)
g++ -shared shapes.o shapesModule_wrap.o $(python-config --ldflags) -o _shapes.so
Note:
shapes.h
. Instead, you need to compile the corresponding implementation file shapes.cpp
that seems to be missing from the example._shapes.so