spack: extra_rpaths in compilers.yaml not working

In #4256, I added a package for OpenBabel. After installation, I ran ldd -r on the libraries and found that they were linking to the wrong libstdc++ library:

$ ldd -r libopenbabel.so
libopenbabel.so: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by libopenbabel.so)
...
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002b47e587d000)

By adding the GCC compiler to my LD_LIBRARY_PATH, I was able to resolve this problem. I tried making the following change in compilers.yaml to do this automatically:

- compiler:
    environment: {}
    extra_rpaths:
    - /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/lib64
    flags: {}
    modules: []
    operating_system: centos6
    paths:
      cc: /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/bin/gcc
      cxx: /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/bin/g++
      f77: /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/bin/gfortran
      fc: /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/bin/gfortran
    spec: gcc@6.1.0
    target: x86_64

but it appears that extra_rpaths isn’t working. I reinstalled Open Babel but it still links to the system libstdc++ instead of the one in $GCC_ROOT/lib64. Adding it manually to LD_LIBRARY_PATH works:

$ ldd -r /blues/gpfs/home/ajstewart/spack/opt/spack/linux-centos6-x86_64/gcc-6.1.0/openbabel-2.4.1-xqe2leslpleij3g7u4dpje7joxcdydjh/lib/libopenbabel.so
...
	libstdc++.so.6 => /soft/spack/opt/spack/linux-x86_64/gcc-5.3.0/gcc-6.1.0-q2zosj3igepi3pjnqt74bwazmptr5gpj/lib64/libstdc++.so.6 (0x00002b4b18855000)

@scheibelp?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 19 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Oh it’s definitely using the compiler wrappers. I added debug messages to the compiler wrappers and it’s showing up.

@scheibelp Added your suggestion but it didn’t help:

diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index aa3c2aa..dae67be 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -328,8 +328,10 @@ IFS=':' read -ra extra_rpaths <<< "$SPACK_COMPILER_EXTRA_RPATHS"
 for extra_rpath in "${extra_rpaths[@]}"; do
     if [[ $mode == ccld ]]; then
         $add_rpaths && args=("$rpath$extra_rpath" "${args[@]}")
+        args=("-L$extra_rpath" "${args[@]}")
     elif [[ $mode == ld ]]; then
         $add_rpaths && args=("-rpath" "$extra_rpath" "${args[@]}")
+        args=("-L$extra_rpath" "${args[@]}")
     fi
 done

I’ll try -DCMAKE_INSTALL_RPATH now.

Update: It looks like extra_rpaths is actually working, at least for Autotools-based packages. I came up with an interesting way to test it:

Take any 2 packages where one depends on the other (I used bzip2 and zip because they build quickly). If I build zip and run ldd -r on the executable, I can see that it links to Spack-built bzip2 properly. Now, uninstall zip, comment out the depends_on('bzip2'), and reinstall zip. As long as you have bzip2-devel installed on the system, zip will link to the system installation. Now, add the directory containing the bzip2 libraries to extra_rpaths in compilers.yaml. When you rebuild, you’ll find that it now links to the Spack-build bzip2 even though it’s not an explicit dependency.

I’m going to test things out with a simple CMake-based package to confirm my suspicion that this is limited to CMake-based packages. We may just need to add extra_rpaths to -DCMAKE_INSTALL_RPATH to solve the original problem I was having.