GeezerVison is showing github.com — BUG: Trouble with `gfortran` and `vscode` · Issue #12448 · mesonbuild/meson
BUG: Trouble with gfortran and vscode #12448DescriptionDescribe the bug
This came up in the context of building python modules over in numpy/numpy#25000 by @jmrohwer.
In essence, for the reproducer below, the problem comes up while building a windows based python.exe module from mixed Fortran and C files.
The Meson build system
Version: 1.2.3
Source dir: C:\Users\jr\Documents\Python\f2py_test\build-windows
Build dir: C:\Users\jr\Documents\Python\f2py_test\build-windows\bbdir
Build type: native build
Project name: hi
Project version: 0.1
Fortran compiler for the host machine: gfortran (gcc 12.2.0 "GNU Fortran (x86_64-posix-seh-rev2, Built by MinGW-W64 project) 12.2.0")
Fortran linker for the host machine: gfortran ld.bfd 2.39
C compiler for the host machine: gcc (gcc 12.2.0 "gcc.exe (x86_64-posix-seh-rev2, Built by MinGW-W64 project) 12.2.0")
C linker for the host machine: gcc ld.bfd 2.39
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (C:\Python312\python.exe)
Run-time dependency python found: YES 3.12
Build targets in project: 1
Found ninja-1.11.1 at C:\ProgramData\chocolatey\bin\ninja.EXE
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\ProgramData\chocolatey\bin\ninja.EXE -C C:/Users/jr/Documents/Python/f2py_test/build-windows/bbdir
ninja: Entering directory `C:/Users/jr/Documents/Python/f2py_test/build-windows/bbdir'
[3/6] Compiling C object hi.cp312-win_amd64.pyd.p/186a87aefc5816048ccf8f910da29dbb8286fc40_.._.._f2py_src_fortranobject.c.obj
C:/Python312/Lib/site-packages/numpy/f2py/src/fortranobject.c: In function 'fortran_doc':
C:/Python312/Lib/site-packages/numpy/f2py/src/fortranobject.c:343:52: warning: unknown conversion type character 'z' in format [-Wformat=]
343 | "fortranobject.c: fortran_doc: len(p)=%zd>%zd=size:"
| ^
C:/Python312/Lib/site-packages/numpy/f2py/src/fortranobject.c:343:56: warning: unknown conversion type character 'z' in format [-Wformat=]
343 | "fortranobject.c: fortran_doc: len(p)=%zd>%zd=size:"
| ^
C:/Python312/Lib/site-packages/numpy/f2py/src/fortranobject.c:343:13: warning: too many arguments for format [-Wformat-extra-args]
343 | "fortranobject.c: fortran_doc: len(p)=%zd>%zd=size:"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[6/6] Linking target hi.cp312-win_amd64.pyd
Note that, this doesn't create a .dll which can be loaded
To Reproduce
I've attached the reproducer from @jmrohwer
build-windows.zip
Expected behavior
distutils used to produce the following:
hi.cp311-win_amd64.pyd
hi\.libs\libhi.LM6TMX7H4VE3WXT3WJV3AXCNAQQAXT2U.gfortran-win_amd64.dll
Which would use gfortran and vscode compilers. However, even with --vscode then the linker fails:
PS C:\Users\jr\Documents\Python\f2py_test> python3.12 -m numpy.f2py -c hi.pyf hi.f --build-dir build-windows
Cannot use distutils backend with Python 3.12, using meson backend instead.Using meson backend
Will pass --lower to f2py
See https://numpy.org/doc/stable/f2py/buildtools/meson.htmlReading fortran codes...
Reading file 'hi.pyf' (format:free)
Post-processing...
Block: hi
Block: hello
Applying post-processing hooks...
character_backward_compatibility_hook
Post-processing (stage 2)...
Building modules...
Building module "hi"...
Generating possibly empty wrappers"
Maybe empty "hi-f2pywrappers.f"
Constructing wrapper function "hello"...
hello()
Wrote C/API module "hi" to file ".\himodule.c"
The Meson build system
Version: 1.2.3
Source dir: C:\Users\jr\Documents\Python\f2py_test\build-windows
Build dir: C:\Users\jr\Documents\Python\f2py_test\build-windows\bbdir
Build type: native build
Project name: hi
Project version: 0.1
Activating VS 17.3.1
Fortran compiler for the host machine: gfortran (gcc 12.2.0 "GNU Fortran (x86_64-posix-seh-rev2, Built by MinGW-W64 project) 12.2.0")
Fortran linker for the host machine: gfortran ld.bfd 2.39
C compiler for the host machine: cl (msvc 19.33.31629 "Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31629 for x64")
C linker for the host machine: link link 14.33.31629.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (C:\Python312\python.exe)
Run-time dependency python found: YES 3.12
Build targets in project: 1
hi 0.1
User defined options
vsenv: True
Found ninja-1.10.2 at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.EXE"
Visual Studio environment is needed to run Ninja. It is recommended to use Meson wrapper:
C:\Python312\Scripts\meson compile -C bbdir
Activating VS 17.3.1
INFO: automatically activated MSVC compiler environment
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.EXE" -C C:/Users/jr/Documents/Python/f2py_test/build-windows/bbdir
ninja: Entering directory `C:/Users/jr/Documents/Python/f2py_test/build-windows/bbdir'
[6/6] Linking target hi.cp312-win_amd64.pyd
FAILED: hi.cp312-win_amd64.pyd
"link" /MACHINE:x64 /OUT:hi.cp312-win_amd64.pyd hi.cp312-win_amd64.pyd.p/hi.f.obj hi.cp312-win_amd64.pyd.p/himodule.c.obj hi.cp312-win_amd64.pyd.p/hi-f2pywrappers.f.obj hi.cp312-win_amd64.pyd.p/186a87aefc5816048ccf8f910da29dbb8286fc40_.._.._f2py_src_fortranobject.c.obj "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/lib" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib" "/LIBPATH:C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../.." "/nologo" "/release" "/nologo" "/OPT:REF" "/DLL" "/IMPLIB:hi.cp312-win_amd64.lib" "C:\Python312\libs\python312.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "gfortran.lib"
LINK : fatal error LNK1181: cannot open input file 'gfortran.lib'
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "c:\python312\Lib\site-packages\numpy\f2py\__main__.py", line 5, in <module>
main()
File "c:\python312\Lib\site-packages\numpy\f2py\f2py2e.py", line 732, in main
run_compile()
File "c:\python312\Lib\site-packages\numpy\f2py\f2py2e.py", line 705, in run_compile
builder.compile()
File "c:\python312\Lib\site-packages\numpy\f2py\_backends\_meson.py", line 132, in compile
self.run_meson(self.build_dir)
File "c:\python312\Lib\site-packages\numpy\f2py\_backends\_meson.py", line 125, in run_meson
raise subprocess.CalledProcessError(
subprocess.CalledProcessError: Command '['meson', 'compile', '-C', 'bbdir']' returned non-zero exit status 1.
system parameters
- Is this a cross build or just a plain native build (for the same computer)?
- what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
- what Python version are you using e.g. 3.8.0
- what
meson --version
- what
ninja --version if it's a Ninja build
More details are in the original issue. Activityeli-schwartz commented on Oct 31, 2023 eli-schwartz commented on Oct 31, 2023
Expected behavior
distutils used to produce the following:
hi.cp311-win_amd64.pyd
hi\\.libs\\libhi.LM6TMX7H4VE3WXT3WJV3AXCNAQQAXT2U.gfortran-win_amd64.dll
Which would use gfortran and vscode compilers. However, even with --vscode then the linker fails:
I assume you mean MSVC (a compiler: Microsoft Visual C++) and not Visual Studio Code (a text editor) or Visual Studio (an IDE that also comes with the Visual C++ compiler bundled)?
Yes, this is all very confusing 🙄 and it doesn't help that meson's option to activate an MSVC environment is called "vsenv" as in "visual studio environment".
As far as the DLL goes, it sounds like the thing that meson isn't "creating" is the gfortran compiler's support DLL which is somewhere inside the compiler installation. This isn't inherently a build system compilation output -- it's part of distributing/packaging. I suspect things like delvewheel would handle this for you.
It's a lot simpler on unixes, where RPATH works to do this sort of thing. :( I'm not sure what the correct answer is for handling dependencies that a compiler injects. rgommers commented on Oct 31, 2023 I think the short answer here is: mixing MSVC and gfortran is not supported. It's in principle possible to build a gfortran compiler that uses the same UCRT libraries as MSVC, but it's very hard to do and there's nothing that works off-the-shelf.
The thing numpy.distutils did in order to glue MSVC(ucrt) and gfortran(mscrt140) together is something I did not attempt to reproduce for Meson, because it's pretty hacky.
You need a compatible compiler toolchain here. So:
- Mingw-w64 C/C++/Fortran compilers
- Intel compilers
- Clang-cl + Flang (this just started working in conda-forge's SciPy build)
- MSVC + Flang
See the "Windows" tab under http://scipy.github.io/devdocs/building/index.html#system-level-dependencies for a bit more detail. Reacted by Rohit Goswami and qi HaoZeke commented on Nov 5, 2023 ContributorAuthor More actions Closing, as described on the original issue, with a compatible toolchain (and a small adjustment to f2py's generated meson.build) everything works.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|