-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
9d6837d removed the ability to link to Fortran_main by default when building -shared libraries. However, building such libraries is how SciPy works under the hood. Shared libraries coming from C/C++/Fortran, which are then accessed from Python.
I managed to build SciPy with flang 17 (bit of a long story), and was now trying to update to flang 18. Aside from issues like #92459, I cannot figure out how to combine -shared with actually linking to Fortran_main. Not that I care particularly about the philosophical aspects of that, but very practically, I get missing symbols without it
[1376/1475] Linking target scipy/linalg/_interpolative.cp310-win_amd64.pyd
FAILED: scipy/linalg/_interpolative.cp310-win_amd64.pyd
"flang-new" -Wl,/OUT:[...objects...] "-Wl,/nologo" "-Wl,/OPT:REF" "-Wl,/DLL" "-Wl,/IMPLIB:scipy\linalg\_interpolative.cp310-win_amd64.lib" "--target=x86_64-pc-windows-msvc" "-fms-runtime-lib=dll" "-fuse-ld=lld" "-Wl,-defaultlib:%PREFIX%/lib/clang/18/lib/windows/clang_rt.builtins-x86_64.lib" "-D_CRT_SECURE_NO_WARNINGS" "-D_MT" "-D_DLL" "--target=x86_64-pc-windows-msvc" "scipy/lib_fortranobject.a" "-Wl,--version-script=C:/bld/scipy-split_1715896809937/work/scipy/_build_utils/link-version-pyinit.map" "%PREFIX%/lib/lapack.lib" "%PREFIX%/lib/blas.lib" "%PREFIX%\libs\python310.lib" "-lFortranRuntime" "-lFortranDecimal"
lld-link: warning: ignoring unknown argument '--version-script=C:/bld/scipy-split_1715896809937/work/scipy/_build_utils/link-version-pyinit.map'
lld-link: error: undefined symbol: _QQmain
Surprisingly, even with a "-lFortran_main" at the end of that invocation, I get the same missing symbols. I've tried a couple of variations but could get none of them to work. The -fno-fortran-main flag mentioned in that PR doesn't seem to have a positive formulation that does enforce linkage to Fortran_main.
As an aside, this is not just for SciPy, relatedly I'm also trying to teach meson how to handle llvm-flang, and this is one of the things I need to figure out how to do. Finally, a lot of the changes from the commit mentioned at the top have been undone in 8d53866, but that came after flang 18. It needs to be possible to do this with released versions (or in the extreme case that it isn't, I need to error out in meson and tell people to upgrade their compiler).