Skip to content

BUG: Clang linker fails on macOS 27 Beta ARM64 — ld: library 'd64' not found #2268

Description

@Bllq21

Describe the issue:

Related issues


Environment

OS macOS 27.0 Developer Beta (arm64)
Chip Apple M3 Pro (11 cores: 5P + 6E), 36GB RAM
Python 3.12.13 (via mise)
PyMC 6.0.1
PyTensor 3.0.7
NumPy 2.4.6
Clang /usr/bin/clang++ (clang-2100.3.23.3)

Root cause (as understood)

-ld64 in pytensor/link/c/cmodule.py is meant to select the classic macOS
linker (ld64) over Apple's new linker (ld/lld). On macOS 27 Beta, Clang
parses this as -l d64 (link against library d64) rather than as a linker
selection flag, because the flag syntax changed in the Xcode toolchain bundled
with this beta OS version.


Workaround (confirmed working)

Setting pytensor.config.cxx = "" before importing PyMC forces PyTensor to
use its Python-mode backend (no C compilation), bypassing the Clang flag entirely.

import pytensor
pytensor.config.cxx = ""  # must be set before `import pymc`
 
import pymc as pm
# ... rest of code works normally

Performance impact on Apple Silicon (M3 Pro, Python-mode vs C-compiled):

  • Observed: ~920 draws/s in Python mode
  • This was sufficient for practical use (1600 draws in ~2 seconds)
  • Python mode may be significantly slower on less capable hardware
    Alternatively, via environment variable before running the script:
export PYTENSOR_FLAGS="cxx="
python your_script.py

Reproducable code example:

python
import pymc as pm
import numpy as np
 
with pm.Model():
    mu = pm.Normal("mu", mu=0, sigma=1)
    pm.sample(100, tune=100, chains=2)

Error message:

pytensor.link.c.exceptions.CompileError: Compilation failed (return status=1):
clang++ -dynamiclib -g -Wno-c++11-narrowing -fno-exceptions -fno-unwind-tables
-fno-asynchronous-unwind-tables -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
-fPIC -undefined dynamic_lookup -ld64
-I/.../numpy/_core/include
-I/.../python3.12/include/python3.12
-I/.../pytensor/link/c/c_code
-L/.../python3.12/lib
-fvisibility=hidden
-o ...lazylinker_ext.so ...mod.cpp
ld: library 'd64' not found
clang++: error: linker command failed with exit code 1

PyTensor version information:

Name: pytensor
Version: 3.0.7

Apple clang version 21.0.0 (clang-2100.3.23.3)
Target: arm64-apple-darwin27.0.0
Thread model: posix

Context for the issue:

This issue appears to affect all recent macOS versions (15.3+, 15.4, and now 27
Beta), with slightly different error messages depending on exact Xcode/Clang
version. The common root is the -ld64 flag in PyTensor's compile command being
incompatible with Apple's evolving linker toolchain. A more robust fix would be
to detect the macOS linker version at compile time and either omit -ld64 or
replace it with -Wl,-ld_classic on macOS versions where the latter is supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions