[C++-sig] Cygwin and boost::python exceptions
Brad Bell
bradbell at seanet.com
Wed Dec 8 16:22:42 CET 2010
There seems to be a problem with the example on
http://www.boost.org/doc/libs/1_45_0/libs/python/doc/v2/exception_translator.html
when I compile it I get the following message:
--------------------------------------------------------------------------
bradbell at apl-9232eef971d ~/pycppad/boost_py
$ g++ -I/usr/include/python2.6 -g -c exception.cpp
exception.cpp: In function `void translate(const my_exception&)':
exception.cpp:14: error: passing `const my_exception' as `this' argument
of `con
st char* my_exception::what()' discards qualifiers
exception.cpp: In function `void something_which_throws()':
exception.cpp:19: error: expected primary-expression before `...' token
exception.cpp:19: error: expected `;' before `...' token
exception.cpp:21: error: expected primary-expression before `...' token
exception.cpp:21: error: expected `;' before `...' token
bradbell at apl-9232eef971d ~/pycppad/boost_py
$ g++ --version
g++ (GCC) 4.3.4 20090804 (release) 1
--------------------------------------------------------------------------
I have figured out a way around this problem, see the attached file
exception.sh. This works fine under unix, but under cygwin, the
exception does not seem to be caught by the python 'except' section of
the 'try' block.
--------------------------------------------------------------------------
Here is the result of running exception.sh under unix:
[bradbell at localhost trash]$ ./exception.sh
cat << EOF > exception.cpp
g++ -I/usr/include/python2.7 -g -c exception.cpp
g++ -shared \
-g \
exception.o \
-L/usr/lib -L/usr/lib/python2.7/config \
-lboost_python-mt -lpython2.7 \
-o exception.so
cat << EOF > exception.py
exception.sh: OK
...
--------------------------------------------------------------------------
Here is the result of running under cygwin:
$ ./exception.sh
cat << EOF > exception.cpp
g++ -I/usr/include/python2.6 -g -c exception.cpp
g++ -shared -Wl,--enable-auto-image-base \
-g \
exception.o \
-L/usr/lib -L/usr/lib/python2.6/config \
-lboost_python-mt -lpython2.6 \
-o exception.dll
cat << EOF > exception.py
terminate called after throwing an instance of 'my_exception'
what(): my error message
./exception.sh: line 97: 2108 Aborted (core dumped)
python exception.py
exception.sh: Error
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: exception.sh
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20101208/3f10e235/attachment.ksh>
More information about the Cplusplus-sig
mailing list