Skip to content

Conversation

@mcmehrtens
Copy link
Member

I use Spack to manage my dependencies for Alamo and keep them separate from my system-installed dependencies which I need for other projects/software. Getting Alamo to find my Spack-installed dependencies during compile/link time was trivial using the --link flag, but the executable couldn't find the libpng dependency during runtime:

RUN    tests/AllenCahn
  ├ 2D-serial-level
  │      Running test............................................[FAIL]
  │      CMD   : ./bin/alamo-2d-clang++ tests/AllenCahn/input stop_time=10.0 plot_file=tests/AllenCahn/output_2025-11-25_18.59.40_matt-mbp-3.local_2D-serial-level
  │      STDOUT:
  │      STDERR: dyld[1690]: Library not loaded: @rpath/libpng16.16.dylib
  │      STDERR:   Referenced from: <BEABEF32-5F95-307E-AC2E-D79FB640690D> /Users/mcmehrtens/code/alamo/bin/alamo-2d-clang++
  │      STDERR:   Reason: no LC_RPATH's found
  │      STDERR:

Looking at the output from otool, I can confirm libpng is being referenced dynamically:

❯ otool -L bin/alamo-2d-clang++
bin/alamo-2d-clang++:
        @rpath/libpng16.16.dylib (compatibility version 16.0.0, current version 16.47.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
        /opt/homebrew/opt/gcc/lib/gcc/current/libgfortran.5.dylib (compatibility version 6.0.0, current version 6.0.0)
        /Users/mcmehrtens/tools/spack/opt/spack/darwin-m1/openmpi-5.0.9-xojzyn7jieqeynwgmsomyybgjtcal3iq/lib/libmpi.40.dylib (compatibility version 81.0.0, current version 81.7.0)
        /opt/homebrew/opt/llvm/lib/c++/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)

But, there doesn't appear to be a path set that would tell the executable where to find my Spack-installed libpng library:

$ otool -l ./bin/alamo-2d-clang++ | grep -A2 LC_RPATH

One fix (as implemented in this PR) would be to add any libraries that were added with --link to the rpath using -Wl,-rpath,/path/to/library. If you do this, then we correctly see the LC_RPATH with otool:

$ otool -l ./bin/alamo-2d-clang++ | grep -A2 LC_RPATH
          cmd LC_RPATH
      cmdsize 48
         path /opt/homebrew/opt/llvm/lib/c++ (offset 12)
--
          cmd LC_RPATH
      cmdsize 56
         path /opt/homebrew/opt/gcc/lib/gcc/current (offset 12)
--
          cmd LC_RPATH
      cmdsize 120
         path /Users/mcmehrtens/tools/spack/opt/spack/darwin-m1/libpng-1.6.47-s4qucbbozbdwq7botwwkeeiknhcn7wzz/lib (offset 12)
--
          cmd LC_RPATH
      cmdsize 112
         path /Users/mcmehrtens/tools/spack/opt/spack/darwin-m1/fftw-3.3.10-6ogec24drajjfbxswvxtrie2ad4sorlw/lib (offset 12)

and we no longer get the error about not being able to find the libpng library:

RUN    tests/AllenCahn
  ├ 2D-serial-level
  │      Running test............................................[PASS] (2.32s)
  │      Checking result.........................................[PASS]

@mcmehrtens mcmehrtens requested a review from bsrunnels November 26, 2025 01:27
@mcmehrtens mcmehrtens self-assigned this Nov 26, 2025
@mcmehrtens mcmehrtens added the bug label Nov 26, 2025
@bsrunnels bsrunnels merged commit 20dd09e into development Nov 26, 2025
21 checks passed
@bsrunnels bsrunnels deleted the bug/add-link-args-to-rpath branch November 26, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants