diff --git a/var/spack/repos/builtin/packages/gcc-runtime/package.py b/var/spack/repos/builtin/packages/gcc-runtime/package.py index 6be91537f6d..2c12f6eee99 100644 --- a/var/spack/repos/builtin/packages/gcc-runtime/package.py +++ b/var/spack/repos/builtin/packages/gcc-runtime/package.py @@ -76,9 +76,8 @@ def install(self, spec, prefix): def _get_libraries_macho(self): """Same as _get_libraries_elf but for Mach-O binaries""" - cc = Executable(self["gcc"].cc) + cc = self._get_compiler() path_and_install_name = [] - for name in self.LIBRARIES: if name == "gcc_s": # On darwin, libgcc_s is versioned and can't be linked as -lgcc_s, @@ -116,6 +115,23 @@ def _get_libraries_macho(self): return path_and_install_name + def _get_compiler(self): + gcc_pkg = self["gcc"] + exe_path = None + for attr_name in ("cc", "cxx", "fortran"): + try: + exe_path = getattr(gcc_pkg, attr_name) + except AttributeError: + pass + + if not exe_path: + continue + cc = Executable(exe_path) + break + else: + raise InstallError(f"cannot find any compiler for {gcc_pkg.spec}") + return cc + @property def libs(self): # Currently these libs are not linkable with -l, they all have a suffix.