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:
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: apple-clang@11.0.0
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
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:
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_rpathsincompilers.yamlsimply solves this problem and givenspack compiler findalready automagically creates the mixed AppleClang+gcc toolchain, I would propose thatspack compiler findalso adds the gfortran lib toextra_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.yamlto provide the path to 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
clangandgfortran, 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 additionextra_pathsshould be added to include the gfortran library path. For example, if gfortan is installed with spack, it would look likeextra_rpaths: /spack-install-prefix/gcc-14.1.0-coujsgwsxtrfjh7nanahdmng7s4ymdok/lib.Error message
No response
Information on your system
macos
General information
spack debug reportand reported the version of Spack/Python/Platform