Skip to content

Fix libmkl_umath_loops.so ImportError under meson-python >= 0.22 - #275

Merged
antonwolfy merged 1 commit into
mainfrom
fix/loops-rpath-install-rpath-hybrid
Sep 28, 2026
Merged

antonwolfy merged 1 commit into
mainfrom
fix/loops-rpath-install-rpath-hybrid

Conversation

@antonwolfy

Copy link
Copy Markdown
Collaborator

Summary

Fixes ImportError: libmkl_umath_loops.so: cannot open shared object file at import time on Linux/macOS when the package is built with meson-python >= 0.22, by adding $ORIGIN (the installed package directory) to the extension modules' -Wl,-rpath link_args.

Root cause

libmkl_umath_loops.so is installed into the mkl_umath package directory, alongside the _ufuncs and _patch_numpy extension modules that link against it. Locating it at import time relied on the $ORIGIN RPATH that Meson auto-inserts for internal link_with dependencies. meson-python 0.22 changed behavior and now strips the RPATH entries Meson inserts, so that $ORIGIN entry disappears from the installed modules and the loader can no longer find the co-located library.

This surfaced once conda-forge shipped meson-python 0.22: test_linux began failing at import mkl_umath across all Python versions, with no code change.

Fix

Add $ORIGIN (@loader_path on macOS) to rpath_link_args in meson.build, next to the existing $ORIGIN/../.. and $ORIGIN/../../.. entries used for the MKL runtime.

Alternatives considered

Migrating to meson-python's install_rpath argument (see #274) is cleaner but requires meson-python >= 0.22, which on conda-forge requires Python >= 3.11 — so it cannot be adopted while the project still builds for Python 3.10. This PR intentionally avoids the floor bump; #274 remains open for when Python 3.10 is dropped.

Add $ORIGIN (the installed package directory) to the -Wl,-rpath link_args
so the extension modules can locate the co-located libmkl_umath_loops.so.

meson-python >= 0.22 strips the $ORIGIN RPATH Meson auto-inserts for
internal link_with dependencies, which caused
'ImportError: libmkl_umath_loops.so: cannot open shared object file' at
import time on Linux/macOS. Passing the entry as a raw link_arg (rather
than install_rpath) has meson-python preserve it on all supported
versions, so the meson-python >= 0.16 floor and Python 3.10 support are
unchanged.

@jharlow-intel jharlow-intel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, like the RPATH comment added to meson.build

@antonwolfy
antonwolfy merged commit cad6be1 into main Sep 28, 2026
146 checks passed
@antonwolfy
antonwolfy deleted the fix/loops-rpath-install-rpath-hybrid branch September 28, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants