In a project, I have to bind C++ code including opengl library in Python with swig. The problem is when I include the OpenGl shared library, the exception handler does not work anymore. As illustration, this project:
example.i
/* example.i */
%module example
%{
#include "example.h"
%}
class Error{
public:
Error();
const char *what() const throw();
virtual ~Error() throw();
};
void foo() throw(Error);
example.cpp
#include"example.h"
Error::Error(){}
const char *Error::what() const throw() { return "FOO"; }
Error::~Error() throw(){}
void foo() throw(Error){throw(Error());}
example.h
class Error{
public:
Error();
const char *what() const throw();
virtual ~Error() throw();
};
void foo() throw(Error);
example.py
from example import *
try:
foo()
except Error,e:
print e.what()
makefile
swig -c++ -python example.i
g++ -I/usr/include/python2.7/ -c -fpic example.cpp example_wrap.cxx
g++ -lGL -shared example.o example_wrap.o -o _example.so
python example.py
With -lGL a segmentation fault occurs. Without, python handles the error. Do you have any idea to solve this problem?