SWIG / Python:使用OpenGL共享库的异常处理程序

时间:2012-07-12 12:09:03

标签: python opengl swig

在一个项目中,我必须将包含opengl库的C ++代码与swig绑定在Python中。问题是当我包含OpenGl共享库时,异常处理程序不再起作用。如图所示,这个项目:

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()

生成文件

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

使用-lGL发生分段错误。没有,python处理错误。 你有什么想法解决这个问题吗?

0 个答案:

没有答案