Repository: spack/spack

Issue:
Installation issue: pexsi +fortran and with openmp in dependencies
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

> spack install pexsi@0.10.2%gcc@8.4.0 +fortran ^superlu-dist@5.3.0%gcc@8.4.0~int64+openmp+shared 

is failing with the error
>    59    (/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/openmpi-3.1.5-e2ui4ckp7p2bs272tcu2wbbqn
           rye7kdl/bin/mpif90 -o f_driver_ksdft_linux f_driver_ksdft.o   /tmp/spackswinst/spack-stage/spack-stage-pexsi
           -0.10.2-dqqtnfp2u6vuwf3636bjykh3363sictk/spack-src/src/libpexsi_linux.a /software/spack-software/2020.05.14/
           linux-rhel8-ivybridge/gcc-8.4.0/superlu-dist-5.3.0-z5awrqmwa27gvmf5pcmyi74kwoprkooa/lib/libsuperlu_dist.a -L
           /software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/parmetis-4.0.3-4uuqa567kah2qlyqhltd5gla5
           xv6fq6p/libparmetis -lparmetis -L/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/metis-5
           .1.0-ltvqgzyk6sxoi5sor4qtioclhmvvcizj/lib -lmetis /software/spack-software/2020.05.14/linux-rhel8-ivybridge/
           gcc-8.4.0/openblas-0.3.9-txqoq5uvoeovialc6oyl5b5phgt7fj2a/lib/libopenblas.so /software/spack-software/2020.0
           5.14/linux-rhel8-ivybridge/gcc-8.4.0/openblas-0.3.9-txqoq5uvoeovialc6oyl5b5phgt7fj2a/lib/libopenblas.so  /so
           ftware/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/openmpi-3.1.5-e2ui4ckp7p2bs272tcu2wbbqnrye7
           kdl/lib/libmpi_cxx.so /software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/openmpi-3.1.5-e2ui
           4ckp7p2bs272tcu2wbbqnrye7kdl/lib/libmpi.so -lstdc++ )
 >  \>\> 60    /usr/bin/ld: /software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/superlu-dist-5.3.0-z5awrqmw
           a27gvmf5pcmyi74kwoprkooa/lib/libsuperlu_dist.a(pdgstrf.c.o): undefined reference to symbol 'omp_get_num_thre
           ads@@@@OMP_1.0'
 >  \>\> 61    //software/spack-software/2020.05.14/linux-rhel8-x86_64/gcc-rh8-8.3.1/gcc-8.4.0-vblibp6qsuo6rbkdn6femxo5kcfn
           wvry/lib64/libgomp.so.1: error adding symbols: DSO missing from command line
 >  \>\> 62    collect2: error: ld returned 1 exit status

I believe this is due to my superlu-dist having the +openmp option (and possibly also due to openblas having threads=openmp variant) but no -fopenmp flag being passed to gfortran.

I believe I can fix this (and will provide a patch to do so) by adding a -fopenmp flag to the gfortran command, but I am not certain if that is the correct way to resolve the issue.  It seems that a better solution would be to have superlu-dist and openblas tell packages that depend on them that they should be using the -fopenmp flag, but I am not sure if that is possible (or how to do so). 

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->

### Information on your system
 spack debug report
* **Spack:** 0.14.2
* **Python:** 3.6.8
* **Platform:** linux-rhel8-ivybridge

<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->
The full spec I am building is attached:
[spack-pesci-spec.txt](https://github.com/spack/spack/files/5190627/spack-pesci-spec.txt)

### Additional information

* [spack-build-env.txt](https://github.com/spack/spack/files/5190630/spack-build-env.txt)
* [spack-build-out.txt](https://github.com/spack/spack/files/5190631/spack-build-out.txt)

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->

No maintainers for document.

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/pexsi/package.py b/var/spack/repos/builtin/packages/pexsi/package.py
--- a/var/spack/repos/builtin/packages/pexsi/package.py
+++ b/var/spack/repos/builtin/packages/pexsi/package.py
@@ -62,14 +62,15 @@ def edit(self, spec, prefix):
             ('@STDCXX_LIB', ' '.join(self.compiler.stdcxx_libs))
         ]
 
+        fldflags = ''
         if '@0.9.2' in self.spec:
-            substitutions.append(
-                ('@FLDFLAGS', '-Wl,--allow-multiple-definition')
-            )
-        else:
-            substitutions.append(
-                ('@FLDFLAGS', '')
-            )
+            fldflags += ' -Wl,--allow-multiple-definition'
+
+        if ('^superlu +openmp' in self.spec
+                or '^openblas threads=openmp' in self.spec):
+            fldflags += ' ' + self.compiler.openmp_flag
+
+        substitutions.append(('@FLDFLAGS', fldflags.lstrip()))
 
         template = join_path(
             os.path.dirname(inspect.getmodule(self).__file__),


Test patch: