-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Macos AppleClang-gcc mixed tool chain should better handle FC rpath #45479
Description
Steps to reproduce
On Macos, mixing AppleClang and gcc toolchains is well supported to have access to a Fortran compiler when using AppleClang for C/C++. However, when building a library with this mixed toolchain that links against @rpath/libgfortran.5.dylib, the gfortran lib path is not added as an rpath. Therefore the binary is broken.
This problem crops up in numerous places including open issues:
- Installation issue: py-scipy has a dependency on libgfortran on macOS? #43905
- Installation issue: openblas, using spack-built gcc on MacOS #42627
Based on @haampie 's comments [1], [2], this behaviour seems to be expected.
As an end user, it is totally unclear as to what is happening and without stumbling through the above linked issues it would be totally opaque how to resolve this common problem.
Because the method of adding gfortran lib to extra_rpaths in compilers.yaml simply solves this problem and given spack compiler find already automagically creates the mixed AppleClang+gcc toolchain, I would propose that spack compiler find also adds the gfortran lib to extra_rpaths. I would further propose that the docs are extended to cover this situation.
A suggested edit that I could make as a PR if found agreeable:
Mixed Toolchains
[...]
5. The only thing left to do is to edit ~/.spack/darwin/compilers.yaml to provide the path to gfortran:
compilers:
- compiler:
# ...
paths:
cc: /usr/bin/clang
cxx: /usr/bin/clang++
f77: /path/to/bin/gfortran
fc: /path/to/bin/gfortran
spec: [email protected]
extra_rpaths: /path/to/lib/gfortran
If you used Spack to install GCC, you can get the installation prefix by spack location -i gcc (this will only work if you have a single version of GCC installed). Whereas for Homebrew, GCC is installed in /usr/local/Cellar/gcc/x.y.z. With the DMG installer, the correct path will be /usr/local/gfortran.
When combining clang and gfortran, the gfortran library path is not added as an rpath by spack's compiler wrappers when the build system links with clang or clang++ instead of gfortran. Therefore, the addition extra_paths should be added to include the gfortran library path. For example, if gfortan is installed with spack, it would look like extra_rpaths: /spack-install-prefix/gcc-14.1.0-coujsgwsxtrfjh7nanahdmng7s4ymdok/lib.
Error message
No response
Information on your system
macos
General information
- I have run
spack debug reportand reported the version of Spack/Python/Platform - I have searched the issues of this repo and believe this is not a duplicate
- I have run the failing commands in debug mode and reported the output