Duplicate LC_RPATH errors on macOS 15.4 Sequoia

After upgrading to macOS 15.4 recently, I am not able to run fenicsx-based codes. I get a lot of dlopen errors regarding duplicate LC_RPATH entries. I installed via conda originally.

**ImportError** : dlopen(/Users/bosmacs/.cache/fenics/libffcx_forms_2776970e29d8246dcb3b0507cb5e1b1509b9e159.cpython-313-darwin.so, 0x0002): tried: '/Users/bosmacs/.cache/fenics/libffcx_forms_2776970e29d8246dcb3b0507cb5e1b1509b9e159.cpython-313-darwin.so' (duplicate LC_RPATH '/Users/bosmacs/Repos/dh-solver/.pixi/envs/default/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/bosmacs/.cache/fenics/libffcx_forms_2776970e29d8246dcb3b0507cb5e1b1509b9e159.cpython-313-darwin.so' (no such file), '/Users/bosmacs/.cache/fenics/libffcx_forms_2776970e29d8246dcb3b0507cb5e1b1509b9e159.cpython-313-darwin.so' (duplicate LC_RPATH '/Users/bosmacs/Repos/dh-solver/.pixi/envs/default/lib')

Removing the .cache/fenics folder does not seem to help, they are simply regenerated. I can confirm with otool that there are duplicate entries:

otool -l ~/.cache/fenics/libffcx_forms_2776970e29d8246dcb3b0507cb5e1b1509b9e159.cpython-313-darwin.so | grep -A3 LC_RPATH
          cmd LC_RPATH
      cmdsize 72
         path /Users/bosmacs/Repos/dh-solver/.pixi/envs/default/lib (offset 12)
Load command 12
          cmd LC_RPATH
      cmdsize 72
         path /Users/bosmacs/Repos/dh-solver/.pixi/envs/default/lib (offset 12)
Load command 13
          cmd LC_RPATH
      cmdsize 72
         path /Users/bosmacs/Repos/dh-solver/.pixi/envs/default/lib (offset 12)
Load command 14

Looks like the issue may stem from Xcode 16.3. I installed 16.2 and set the command line tools to the 16.2 version, and am able to run again.

conda-forge folks are working on a fix, but it should work to patch your libgfortran with this script:

import os
from subprocess import run

import lief


def patch(path):
    fat = lief.MachO.parse(path)
    thin = fat.take(lief.MachO.CPU_TYPES.ARM64)
    thin.commands[9].sdk = [11, 0, 0]
    thin.write(path)
    run(["codesign", "-f", "-s", "-", path], check=True)


prefix_lib = os.path.join(os.environ["CONDA_PREFIX"], "lib")

for libname in [
    "libgfortran.5.dylib",
    "libquadmath.0.dylib",
]:
    lib_path = os.path.join(prefix_lib, libname)
    print(f"Patching {lib_path}")
    patch(lib_path)

(requires py-lief=0.14.*)

WARNING: be prepared to recreate your env if patching any libraries like this

Thanks! Forgot to mention I had the same issue with libgfortran, and fixed in a similar manner, with

install_name_tool -delete_rpath "@loader_path" /path/to/libgfortran.dylib

and re-signing with codesign. Your script simplifies the process.

What I was pointing out is the same problem appears with dylibs generated by just-in-time compilations of FFCX forms, it appears.

I’m having the same issue after updating to macOS 15.4. I was able to patch libgfortran with a batch script that I found here: https://github.com/conda-forge/numpy-feedstock/issues/347#issuecomment-2746317575, but the problem persist with dylibs generated by just-in-time compilations of FFCX forms.

Yes, I’ve just discovered the same problem applies to ffcx outputs because rpaths are duplicated from Python’s LDSHARED and the default $LDFLAGS. That makes removing them more complex. I believe you can fix it by setting the $LDSHARED environment variable:

export LDSHARED="$CC -bundle -undefined dynamic_lookup"

which has some duplicate -Wl,-rpath entries by default (see sysconfig.get_config_var("LDSHARED").

This won’t affect cached builds, so you’ll need to either clear your cache or patch cached files in-place with a script like this one.

1 Like

status update:

  • libgfortran is fixed if you have libgfortran5=14.* This should be the default for most folks with recently updated or created envs, but if your env hasn’t had an update in a while, conda update libgfortran5 should do it
  • The linker has been fixed to turn these duplicate rpaths into warnings (as the new default Apple linker has been doing since xcode 15), so if you update ld64 to at least build 6 (ld64=951.9=h4c6efb1_6 on mac arm)

So in short, an env should be fixed with:

mamba update libgfortran5 ld64

without needing to patch anything. You may need to clean your ffcx cache.

Thanks, cleaning the cache and updating the packages finally solved my problem.
(I needed to force the ld64 version in the update command to make it work.)