numpy / numpy/numpy

f2py fails to link program on windows using v1.26.0 - works on earlier versions of numpy

Open
#26,352 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug component: numpy.f2py
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Describe the issue:

I have an old fortran program that I access from python using f2py. I have used this successfully on both linux and windows. I have moved successfully to 1.26 on linux but get a link error (1120 unresolved externals) on windows 11. I replicated the problem using a basic fibonacci fortran program (below)

Reproduce the code example:
subroutine fib(a, n)
  use iso_c_binding
   integer(c_int), intent(in) :: n
   integer(c_int), intent(out) :: a(n)
   do i = 1, n
      if (i .eq. 1) then
         a(i) = 0.0d0
      elseif (i .eq. 2) then
         a(i) = 1.0d0
      else
         a(i) = a(i - 1) + a(i - 2)
      end if
   end do
end
Error message:
(aov) C:\fib_test>f2py -c fib1.f90 -m fib1 --backend meson
Using meson backend
Will pass --lower to f2py
See https://numpy.org/doc/stable/f2py/buildtools/meson.htmlReading fortran codes...
        Reading file 'fib1.f90' (format:free)
Post-processing...
        Block: fib1
                        Block: fib
In: :fib1:fib1.f90:fib
get_useparameters: no module iso_c_binding info used by fib
Applying post-processing hooks...
  character_backward_compatibility_hook
Post-processing (stage 2)...
Building modules...
    Building module "fib1"...
    Generating possibly empty wrappers"
    Maybe empty "fib1-f2pywrappers.f"
        Constructing wrapper function "fib"...
          a = fib(n)
    Wrote C/API module "fib1" to file ".\fib1module.c"
The Meson build system
Version: 1.2.1
Source dir: C:\Users\keith\AppData\Local\Temp\tmp679okcip
Build dir: C:\Users\keith\AppData\Local\Temp\tmp679okcip\bbdir
Build type: native build
Project name: fib1
Project version: 0.1
Fortran compiler for the host machine: ifx (intel-llvm-cl 2022.1.0)
Fortran linker for the host machine: xilink.exe xilink 2022.1.0
C compiler for the host machine: cl (msvc 19.29.30146 "Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30146 for x64")
C linker for the host machine: link link 14.29.30146.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (C:\Users\keith\anaconda3\envs\aov\python.exe)
Run-time dependency python found: YES 3.12
Build targets in project: 1

Found ninja-1.10.2 at C:\Users\keith\anaconda3\envs\aov\Library\bin\ninja.EXE
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\keith\anaconda3\envs\aov\Library\bin\ninja.EXE -C C:/Users/keith/AppData/Local/Temp/tmp679okcip/bbdir
ninja: Entering directory `C:/Users/keith/AppData/Local/Temp/tmp679okcip/bbdir'
[4/6] Compiling Fortran object fib1.cp312-win_amd64.pyd.p/fib1-f2pywrappers.f.obj
../fib1-f2pywrappers.f: remark #5133: The input stream is empty
[6/6] Linking target fib1.cp312-win_amd64.pyd
FAILED: fib1.cp312-win_amd64.pyd
"link"  /MACHINE:x64 /OUT:fib1.cp312-win_amd64.pyd fib1.cp312-win_amd64.pyd.p/fib1.f90.obj fib1.cp312-win_amd64.pyd.p/fib1module.c.obj fib1.cp312-win_amd64.pyd.p/fib1-f2pywrappers.f.obj fib1.cp312-win_amd64.pyd.p/42bc432c09fd0a50dc493f9b8a0dabb66e5dad74_.._.._f2py_src_fortranobject.c.obj "/nologo" "/release" "/nologo" "/OPT:REF" "/DLL" "/IMPLIB:fib1.cp312-win_amd64.lib" "-shared" "C:\Users\keith\anaconda3\envs\aov\libs\python312.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"
LINK : warning LNK4044: unrecognized option '/shared'; ignored
   Creating library fib1.cp312-win_amd64.lib and object fib1.cp312-win_amd64.exp
fib1module.c.obj : error LNK2001: unresolved external symbol fib_
fib1.cp312-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "C:\Users\keith\anaconda3\envs\aov\Scripts\f2py-script.py", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "C:\Users\keith\anaconda3\envs\aov\Lib\site-packages\numpy\f2py\f2py2e.py", line 732, in main
    run_compile()
  File "C:\Users\keith\anaconda3\envs\aov\Lib\site-packages\numpy\f2py\f2py2e.py", line 705, in run_compile
    builder.compile()
  File "C:\Users\keith\anaconda3\envs\aov\Lib\site-packages\numpy\f2py\_backends\_meson.py", line 131, in compile
    self.run_meson(self.build_dir)
  File "C:\Users\keith\anaconda3\envs\aov\Lib\site-packages\numpy\f2py\_backends\_meson.py", line 124, in run_meson
    raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['meson', 'compile', '-C', 'bbdir']' returned non-zero exit status 1.
Python and NumPy Versions:

python 3.12.3
Numpy 1.26.0

Runtime Environment:

(aov) C:\Users\keith\temp\fib_test>python -c "import numpy; print(numpy.show_runtime())"
[{'numpy_version': '1.26.0',
'python': '3.12.3 | packaged by Anaconda, Inc. | (main, Apr 19 2024, '
'16:41:55) [MSC v.1916 64 bit (AMD64)]',
'uname': uname_result(system='Windows', node='LENNY2', release='11', version='10.0.22631', machine='AMD64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'filepath': 'C:\Users\keith\anaconda3\envs\aov\Library\bin\mkl_rt.2.dll',
'internal_api': 'mkl',
'num_threads': 8,
'prefix': 'mkl_rt',
'threading_layer': 'intel',
'user_api': 'blas',
'version': '2023.1-Product'}]
None

Context for the issue:

A user has upgraded to python 3.12 and cannot use our product

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in numpy/f2py/_backends/_meson.py and reproduce the reported f2py -c fib1.f90 -m fib1 --backend meson command on Windows. Inspect the generated link command and compare it with earlier NumPy versions to identify why fib_ is unresolved; done means the Fibonacci example builds and imports successfully with NumPy 1.26.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran, python
Domain
build-system, compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.