3

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?

Ramchandra Apte
  • 4,033
  • 2
  • 24
  • 44
Vincent
  • 63
  • 6
  • No I use the native opengl library. – Vincent Aug 06 '12 at 07:56
  • @Vincent Could this be related to this: http://stackoverflow.com/questions/2778193/segfault-during-cxa-allocate-exception-in-swig-wrapped-library ? Perhaps you could find out if opengl has static tls anywhere? – Steve Lorimer Sep 04 '12 at 07:12

0 Answers0