[Numpy-discussion] SWIG examples from the Cookbook

K. B. kanterburiad at gmail.com
Tue Feb 1 11:38:29 EST 2011

I asked a question on this mailing list few days ago but nobody could help me.
So I wonder if it is more appropriate to post this question on the
Scipy-Dev mailing list or to fill a bug repport.
Thank you !


original post :

I'd like to ask for your help regarding the use of SWIG with numpy.

** problem description **
While I can compile successfully the examples provided in ./numpy/doc/swig

I can't compile the first example provided in the Cookbook.


"A simple ARGOUT_ARRAY1 example"

I have this error:
ezrange_wrap.c: In function ‘SWIG_AsVal_long’:
ezrange_wrap.c:3227: error: initializer element is not constant

** hypothesis and ugly workaround **
Comparing the examples from ./numpy/doc/swig and from the Cookbook, I
noticed the main difference lies in the fact the first are in C++ while the
latter in plain C.

I "converted" the example from the Coobook to look like a c++ project.
Essentially I renamed the .c file with a .cxx extension and I modified
setup.py accordingly.
This time it compiles successfully and the module is usable in python.

** questions **
1/ What should I do to compile the Cookbook example with a C compiler?

2/ If it appears swig is now only compatible with the C++ compiler, do you
have a practical workaround to propose? (without renaming the C files with a
.cxx extension) ?

** configuration **
debian testing i686
swig version 1.3.40
python-numpy version 1.5.1 (I also tried 1.4.1)
python version 2.6

More information about the NumPy-Discussion mailing list