Skip to content

BUG: f2py compile fail, require C99 standard #22572

@Songningw99

Description

@Songningw99

Describe the issue:

After I ran f2py -c test_sub.f90 test_sub.pyf, I got an error compiling the codes:

......
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c:707:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (int i = 0; i < rank; ++i) {
     ^
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c:707:5: note: use option -std=c99 or -std=gnu99 to compile your code
error: Command "gcc -pthread -B /data/keeling/a/songning/miniconda3/envs/default/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC -DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmphlgqv6nk/src.linux-x86_64-3.8 -I/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include -I/data/keeling/a/songning/miniconda3/envs/default/include/python3.8 -c /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c -o /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.o -MMD -MF /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.o.d" failed with exit status 1

I don't find an entrance to pass -std=c99, is there any specific reason that the int i = 0 parameter is place inside for statement here rather than make the statement before for? I don't remember seeing this error in the earlier version.

# f2py -v
1.23.4

My codes if it's needed:
test_sub.f90:

subroutine test_sub(a)
    use:: ISO_FORTRAN_ENV
    use:: IEEE_ARITHMETIC, only: ieee_support_nan, ieee_is_nan, &
                                            ieee_quiet_nan, ieee_value

    implicit none
    real(real32), dimension(:), intent(in):: a
    integer(int32):: n=len(a)

    do i = 1:n 
        write(*, *) i, ieee_is_nan(a(i))
    end do

end subroutine test_sub

test_sub.pyf:

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module test_sub ! in 
    interface  ! in :test_sub
        subroutine test_sub(a) ! in :test_sub:test_sub.f90
            real(kind=real32) dimension(:),intent(in) :: a
        end subroutine test_sub
    end interface 
end python module test_sub

! This file was auto-generated with f2py (version:1.22.4).
! See:
! https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e

Reproduce the code example:

!f2py -c test_sub.f90 test_sub.pyf

Error message:

running build
running config_cc
INFO: unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
INFO: unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
INFO: build_src
INFO: building extension "test_sub" sources
creating /tmp/tmphlgqv6nk/src.linux-x86_64-3.8
INFO: f2py options: []
INFO: f2py: test_sub.pyf
Reading fortran codes...
        Reading file 'test_sub.pyf' (format:free)
Post-processing...
        Block: test_sub
                        Block: test_sub
Post-processing (stage 2)...
Building modules...
    Building module "test_sub"...
    Generating possibly empty wrappers"
    Maybe empty "test_sub-f2pywrappers2.f90"
    Maybe empty "test_sub-f2pywrappers.f"
                Creating wrapper for Fortran subroutine "test_sub"("test_sub")...
        Constructing wrapper function "test_sub"...
getctype: "real(kind=real32)" is mapped to C "float" (to override define dict(real = dict(real32="<C typespec>")) in /data/jtrapp/a/songning/f_cape/.f2py_f2cmap file).
getctype: "real(kind=real32)" is mapped to C "float" (to override define dict(real = dict(real32="<C typespec>")) in /data/jtrapp/a/songning/f_cape/.f2py_f2cmap file).
getctype: "real(kind=real32)" is mapped to C "float" (to override define dict(real = dict(real32="<C typespec>")) in /data/jtrapp/a/songning/f_cape/.f2py_f2cmap file).
          test_sub(a)
    Wrote C/API module "test_sub" to file "/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_submodule.c"
    Fortran 90 wrappers are saved to "/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_sub-f2pywrappers2.f90"
INFO:   adding '/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c' to sources.
INFO:   adding '/tmp/tmphlgqv6nk/src.linux-x86_64-3.8' to include_dirs.
copying /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmphlgqv6nk/src.linux-x86_64-3.8
copying /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmphlgqv6nk/src.linux-x86_64-3.8
INFO:   adding '/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_sub-f2pywrappers.f' to sources.
INFO:   adding '/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_sub-f2pywrappers2.f90' to sources.
INFO: build_src: building npy-pkg config files
/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running build_ext
INFO: customize UnixCCompiler
INFO: customize UnixCCompiler using build_ext
INFO: get_default_fcompiler: matching types: '['arm', 'gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu']'
INFO: customize ArmFlangCompiler
WARN: Could not locate executable armflang
INFO: customize Gnu95FCompiler
INFO: Found executable /usr/bin/gfortran
INFO: customize Gnu95FCompiler
INFO: customize Gnu95FCompiler using build_ext
INFO: building 'test_sub' extension
INFO: compiling C sources
INFO: C compiler: gcc -pthread -B /data/keeling/a/songning/miniconda3/envs/default/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC

creating /tmp/tmphlgqv6nk/tmp
creating /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk
creating /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk/src.linux-x86_64-3.8
INFO: compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmphlgqv6nk/src.linux-x86_64-3.8 -I/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include -I/data/keeling/a/songning/miniconda3/envs/default/include/python3.8 -c'
INFO: gcc: /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_submodule.c
INFO: gcc: /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c
In file included from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1948:0,
                 from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.h:13,
                 from /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c:2:
/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^
In file included from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1948:0,
                 from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.h:13,
                 from /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_submodule.c:23:
/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/test_submodule.c:144:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
 static int f2py_size(PyArrayObject* var, ...)
            ^
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c: In function ‘find_first_negative_dimension’:
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c:707:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (int i = 0; i < rank; ++i) {
     ^
/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c:707:5: note: use option -std=c99 or -std=gnu99 to compile your code
error: Command "gcc -pthread -B /data/keeling/a/songning/miniconda3/envs/default/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC -O2 -isystem /data/keeling/a/songning/miniconda3/envs/default/include -fPIC -DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmphlgqv6nk/src.linux-x86_64-3.8 -I/data/keeling/a/songning/miniconda3/envs/default/lib/python3.8/site-packages/numpy/core/include -I/data/keeling/a/songning/miniconda3/envs/default/include/python3.8 -c /tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.c -o /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.o -MMD -MF /tmp/tmphlgqv6nk/tmp/tmphlgqv6nk/src.linux-x86_64-3.8/fortranobject.o.d" failed with exit status 1

NumPy/Python version information:

1.23.4
3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)
[GCC 10.3.0]

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions