Repository: spack/spack

Issue:
Installation issue: gmt@5.4.4 %gcc@11.1.0
### Steps to reproduce the issue

```console
spack install gmt@5.4.4 %gcc@11.1.0
```
results in the following error, possibly because of an incompatibility with the compiler version
```
==> Installing gmt-5.4.4-e2nhnrqrlxqwjtwonvrumozmqvsjqyuo
==> No binary for gmt-5.4.4-e2nhnrqrlxqwjtwonvrumozmqvsjqyuo found: installing from source
==> Fetching https://mirror.spack.io/_source-cache/archive/b5/b593dfb101e6507c467619f3d2190a9f78b09d49fe2c27799750b8c4c0cd2da0.tar.gz
==> No patches needed for gmt
==> gmt: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j10'

4 errors found in build log:
     936    **/usr/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information.**
     937    CMakeFiles/supplib.dir/potential/grdgravmag3d.c.o:(.bss+0x0): multiple definition of `okabe_mag_var'
     938    /usr/bin/ld: Dwarf Error: found dwarf version '3072', this reader only handles version 2, 3 and 4 information.
     939    CMakeFiles/supplib.dir/potential/okbfuns.c.o:(.bss+0x0): first defined here
     940    CMakeFiles/supplib.dir/potential/grdgravmag3d.c.o:(.bss+0x8): multiple definition of `okabe_mag_param'
     941    CMakeFiles/supplib.dir/potential/okbfuns.c.o:(.bss+0x8): first defined here
  >> 942    collect2: error: ld returned 1 exit status
  >> 943    make[2]: *** [src/plugins/supplements.so] Error 1
     944    make[2]: Leaving directory `/att/gpfsfs/briskfs01/ppl/sberton2/.tmp/spack-stage/spack-stage-gmt-5.4.4-e2nhnrqrlxqwjtwonvrumozmqvsjqyuo/spack-src/spack-build'
  >> 945    make[1]: *** [src/CMakeFiles/supplib.dir/all] Error 2
     946    make[1]: *** Waiting for unfinished jobs....
     947    make[2]: Leaving directory `/att/gpfsfs/briskfs01/ppl/sberton2/.tmp/spack-stage/spack-stage-gmt-5.4.4-e2nhnrqrlxqwjtwonvrumozmqvsjqyuo/spack-src/spack-build'
     948    [ 96%] Built target gmt
     949    make[1]: Leaving directory `/att/gpfsfs/briskfs01/ppl/sberton2/.tmp/spack-stage/spack-stage-gmt-5.4.4-e2nhnrqrlxqwjtwonvrumozmqvsjqyuo/spack-src/spack-build'
  >> 950    make: *** [all] Error 2
```


### Information on your system

* **Spack:** 0.16.3-4760-b33a092
* **Python:** 3.6.8
* **Platform:** linux-centos7-broadwell
* **Concretizer:** clingo

### Additional information

Googling around, I found these pages which look relevant, but I'm unsure how to configure the package with the appropriate GLIBc option (GLIBC_EXTRA_CFLAGS) to produce gdwarf <=4
[https://github.com/crosstool-ng/crosstool-ng/issues/1546](https://github.com/crosstool-ng/crosstool-ng/issues/1546)
[https://gcc.gnu.org/gcc-11/changes.html](https://gcc.gnu.org/gcc-11/changes.html)

@adamjstewart it would be great if you could help! Thanks!

[spack-build-env.txt](https://github.com/spack/spack/files/7324562/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/7324563/spack-build-out.txt)



### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
Does this bug occur for newer versions of gmt?
Not for 6.2.0 or the latest git, at least (I didn't try 6.0.0). The problem is that for some gmt functions, we are having back-compatibility issues, and we need 5.4.2 installed, too...
Not sure how to fix this, reinstalling with gcc@7.4.0 "solved" the issue.
I think the "fix" is to add a conflict to denote that older versions of GMT can't be built with newer versions of GCC. If anyone can backport a patch to add GCC 11 support to older GMT then we can remove the conflict.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gmt/package.py b/var/spack/repos/builtin/packages/gmt/package.py
--- a/var/spack/repos/builtin/packages/gmt/package.py
+++ b/var/spack/repos/builtin/packages/gmt/package.py
@@ -62,6 +62,10 @@ class Gmt(Package):
 
     depends_on('graphicsmagick', type='test')
 
+    # https://github.com/spack/spack/issues/26661
+    conflicts('%gcc@11:', when='@:5',
+              msg='GMT 5 cannot be built with GCC 11+, try a newer GMT or older GCC')
+
     # https://github.com/GenericMappingTools/gmt/pull/3603
     patch('regexp.patch', when='@6.1.0')
     patch('type.patch', when='@4.5.9')


Test patch: