Issue 1706381: SWIG options not being followed in all cases (original) (raw)
I guess this is an undocumented feature, so maybe I shouldn't complain (but the patch to the docs has been in the patch tracker waiting to go in since 2004 it seems).
Default for SWIG is to produce C code, in a file called xxx_wrap.c. If you want C++, you need to specify the -c++ option (in which case you would normally want a file called xxx_wrap.cpp).
You can specify this option in two ways, either on the commandline, like so:
python setup.py build_ext --swig-opts="-c++"
or as an option to your Extention module in setup.py like so: ... ext_modules = [Extension("_xxx", ["xxx.i","xxx.cpp"], swig_opts=["-c++"])] ...
The latter is much preferable, as it doesn't mean you have to remember to specify the option on the commandline all the time.
When specifying on the commandline, the -c++ is taken into account for creating the name of the output, and you get a file called xxx_wrap.cpp. Specifying the option in setup.py however, is not taken into account, and you get a file called xxx_wrap.c, which contains C++ code and generally doesn't compile (since the compiler assumes it's pure C).
I've attached a simple patch that seems to solve the problem.