Error in setup.py When Compiling a C Function?

663 views
Skip to first unread message

Shalom Rav

unread,
Jul 24, 2011, 7:16:24 PM7/24/11
to cython-users
I have a standard setup.py file that is used to compile a single C
source file and have its functions available to interact with Python
code.

When compiling ("python setup.py build_ext --inplace"), I am getting
the following error:
______________________________
GetValue.c: In function ‘JustGet’:
GetValue.c:24: error: ‘for’ loop initial declarations are only allowed
in C99 mode
GetValue.c:24: note: use option -std=c99 or -std=gnu99 to compile your
code
______________________________

It appears that the following line within 'JustGet()' function in the
'c' code is the issue:

for(int j = 0; j < nValues; ++j )
{
......
......
}

(the initialization of 'j' inside the loop causes the error; if I
initialize j before the loop -- the compilation is OK)

_____________________________________________

Is there anything I can change / modify in Distutils to ALLOW the
compilation of c source files where a variable is initialized within a
for loop (like in the case above)?

Just in case it helps, I am using Ubuntu 10.04. Thanks in advance.

Blair Bonnett

unread,
Jul 24, 2011, 8:09:20 PM7/24/11
to cython...@googlegroups.com
As the error message says, you need to add the 'std=c99' flag when compiling. To do this, pass it in to the Extension() call in your setup.py using the 'extra_compile_args' keyword.

Using the basic setup.py given in the Cython docs as an example:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("hello", ["hello.pyx"], extra_compile_args=['-std=c99'])]

setup(
  name = 'Hello world app',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)

Blair

Shalom Rav

unread,
Jul 24, 2011, 9:23:49 PM7/24/11
to cython-users
Blair,

Thank you for this -- it is exactly what I needed.

Best,
Shalom.

On Jul 24, 8:09 pm, Blair Bonnett <blair.bonn...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages