Repository: spack/spack

Issue:
"spack install silo ^hdf5~mpi~shared" fails due to missing -ldl flag
According to [a response on the hdf5 mailing list](https://lists.hdfgroup.org/pipermail/hdf-forum_lists.hdfgroup.org/2013-October/007240.html), hdf5 >= 1.8.11 requires libdl. Attempting

```console
$ spack install silo ^hdf5~mpi~shared
``` 
(~mpi added to reduce build time and is not required to reproduce, but ~shared _is_ required to reproduce) causes silo to fail during configure with undefined reference to 'dlsym', 'dlopen', etc. during a conftest where it looks for H5open in the supplied libhdf5.a.

### Expected Result
Successful silo install
### Actual Result

```console
$ git clone https://github.com/spack/spack.git
$ ./spack/bin/spack install silo ^hdf5~mpi~shared
==> Installing zlib
==> Using cached archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/cache/zlib/zlib-1.2.11.tar.gz
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/zlib-1.2.11.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur
==> No patches needed for zlib
==> Building zlib [Package]
==> Executing phase: 'install'
==> Successfully installed zlib
  Fetch: 0.09s.  Build: 16.54s.  Total: 16.64s.
[+] /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur
==> Installing hdf5
==> Fetching https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.1/src/hdf5-1.10.1.tar.gz
######################################################################## 100.0%
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/hdf5-1.10.1.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn
==> No patches needed for hdf5
==> Building hdf5 [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Executing phase: 'install'
==> Successfully installed hdf5
  Fetch: 14.94s.  Build: 2m 22.22s.  Total: 2m 37.16s.
[+] /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn
==> Installing silo
==> Fetching https://wci.llnl.gov/content/assets/docs/simulation/computer-codes/silo/silo-4.10.2/silo-4.10.2.tar.gz
######################################################################## 100.0%
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie/silo-4.10.2.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie
==> Applied patch remove-mpiposix.patch
==> Building silo [Package]
==> Executing phase: 'install'
==> Error: ProcessError: Command exited with status 1:
    './configure' '--prefix=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie' '--with-hdf5=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/include,/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib' '--with-zlib=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/include,/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/lib' '--enable-install-lite-headers' '--enable-fortran' '--disable-silex' '--enable-shared' 'CFLAGS=-fPIC' 'CXXFLAGS=-fPIC' 'FCFLAGS=-fPIC'

1 error found in build log:
     191    checking for H5open... no
     192    configure: checking if lack of zlib caused tests for hdf5 to fail...
     193    checking hdf5.h usability... yes
     194    checking hdf5.h presence... yes
     195    checking for hdf5.h... yes
     196    checking for H5open in -lhdf5... no
  >> 197    configure: error:
     198    You have made an explicit request for hdf5 with the --with-hdf option
     199    and ./configure is unable to find hdf5 and its supporting libs, if any.
     200    Please see INSTALL_FAQ for possible causes.
```

Here is the failed conftest, copied from config.log
```console
configure:28869: checking for H5open
configure:28933: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/lib/spack/env/gcc/gcc -o conftest -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wdeclaration-after-statement -I/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/include  -I/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/include -L/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib  -L/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/lib conftest.c -lhdf5 -lz  -lz -lm >&5
/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib/libhdf5.a(H5PL.o): In function `H5PL_term_package':
H5PL.c:(.text+0xb2): undefined reference to `dlclose'
/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib/libhdf5.a(H5PL.o): In function `H5PL_load':
H5PL.c:(.text+0x5b2): undefined reference to `dlsym'
H5PL.c:(.text+0x797): undefined reference to `dlopen'
H5PL.c:(.text+0x7b2): undefined reference to `dlsym'
H5PL.c:(.text+0x7e9): undefined reference to `dlclose'
H5PL.c:(.text+0x8f1): undefined reference to `dlerror'
H5PL.c:(.text+0xb73): undefined reference to `dlclose'
```

### Steps to reproduce the issue

```console
$ git clone https://github.com/spack/spack.git
$ ./spack/bin/spack install silo ^hdf5~mpi~shared
```

### Information on your system
LLNL toss3 system **rzgenie**, empty ~/.spack directory
"spack install silo ^hdf5~mpi~shared" fails due to missing -ldl flag
According to [a response on the hdf5 mailing list](https://lists.hdfgroup.org/pipermail/hdf-forum_lists.hdfgroup.org/2013-October/007240.html), hdf5 >= 1.8.11 requires libdl. Attempting

```console
$ spack install silo ^hdf5~mpi~shared
``` 
(~mpi added to reduce build time and is not required to reproduce, but ~shared _is_ required to reproduce) causes silo to fail during configure with undefined reference to 'dlsym', 'dlopen', etc. during a conftest where it looks for H5open in the supplied libhdf5.a.

### Expected Result
Successful silo install
### Actual Result

```console
$ git clone https://github.com/spack/spack.git
$ ./spack/bin/spack install silo ^hdf5~mpi~shared
==> Installing zlib
==> Using cached archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/cache/zlib/zlib-1.2.11.tar.gz
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/zlib-1.2.11.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur
==> No patches needed for zlib
==> Building zlib [Package]
==> Executing phase: 'install'
==> Successfully installed zlib
  Fetch: 0.09s.  Build: 16.54s.  Total: 16.64s.
[+] /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur
==> Installing hdf5
==> Fetching https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.1/src/hdf5-1.10.1.tar.gz
######################################################################## 100.0%
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/hdf5-1.10.1.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn
==> No patches needed for hdf5
==> Building hdf5 [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Executing phase: 'install'
==> Successfully installed hdf5
  Fetch: 14.94s.  Build: 2m 22.22s.  Total: 2m 37.16s.
[+] /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn
==> Installing silo
==> Fetching https://wci.llnl.gov/content/assets/docs/simulation/computer-codes/silo/silo-4.10.2/silo-4.10.2.tar.gz
######################################################################## 100.0%
==> Staging archive: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie/silo-4.10.2.tar.gz
==> Created stage in /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/var/spack/stage/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie
==> Applied patch remove-mpiposix.patch
==> Building silo [Package]
==> Executing phase: 'install'
==> Error: ProcessError: Command exited with status 1:
    './configure' '--prefix=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/silo-4.10.2-nctk3nlpkb3hxkxdnrbdspsgllqtr3ie' '--with-hdf5=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/include,/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib' '--with-zlib=/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/include,/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/lib' '--enable-install-lite-headers' '--enable-fortran' '--disable-silex' '--enable-shared' 'CFLAGS=-fPIC' 'CXXFLAGS=-fPIC' 'FCFLAGS=-fPIC'

1 error found in build log:
     191    checking for H5open... no
     192    configure: checking if lack of zlib caused tests for hdf5 to fail...
     193    checking hdf5.h usability... yes
     194    checking hdf5.h presence... yes
     195    checking for hdf5.h... yes
     196    checking for H5open in -lhdf5... no
  >> 197    configure: error:
     198    You have made an explicit request for hdf5 with the --with-hdf option
     199    and ./configure is unable to find hdf5 and its supporting libs, if any.
     200    Please see INSTALL_FAQ for possible causes.
```

Here is the failed conftest, copied from config.log
```console
configure:28869: checking for H5open
configure:28933: /usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/lib/spack/env/gcc/gcc -o conftest -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wdeclaration-after-statement -I/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/include  -I/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/include -L/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib  -L/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/zlib-1.2.11-3r4cfkmx3wwfqeof4bc244yduu2mz4ur/lib conftest.c -lhdf5 -lz  -lz -lm >&5
/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib/libhdf5.a(H5PL.o): In function `H5PL_term_package':
H5PL.c:(.text+0xb2): undefined reference to `dlclose'
/usr/workspace/wsrzc/pozulp1/sp/reprospack/spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/hdf5-1.10.1-pa7j66e6mfu6qfkgfrus7zuppvirktnn/lib/libhdf5.a(H5PL.o): In function `H5PL_load':
H5PL.c:(.text+0x5b2): undefined reference to `dlsym'
H5PL.c:(.text+0x797): undefined reference to `dlopen'
H5PL.c:(.text+0x7b2): undefined reference to `dlsym'
H5PL.c:(.text+0x7e9): undefined reference to `dlclose'
H5PL.c:(.text+0x8f1): undefined reference to `dlerror'
H5PL.c:(.text+0xb73): undefined reference to `dlclose'
```

### Steps to reproduce the issue

```console
$ git clone https://github.com/spack/spack.git
$ ./spack/bin/spack install silo ^hdf5~mpi~shared
```

### Information on your system
LLNL toss3 system **rzgenie**, empty ~/.spack directory


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/silo/package.py b/var/spack/repos/builtin/packages/silo/package.py
--- a/var/spack/repos/builtin/packages/silo/package.py
+++ b/var/spack/repos/builtin/packages/silo/package.py
@@ -48,6 +48,11 @@ class Silo(Package):
 
     patch('remove-mpiposix.patch', when='@4.8:4.10.2')
 
+    def flag_handler(self, name, flags):
+        if name == 'ldflags' and self.spec['hdf5'].satisfies('~shared'):
+            flags.append('-ldl')
+        return (flags, None, None)
+
     def install(self, spec, prefix):
         config_args = [
             '--enable-fortran' if '+fortran' in spec else '--disable-fortran',


Test patch: