Skip to content

Commit 302b63b

Browse files
LutzGrossclaude
andcommitted
Fix macOS OpenMP duplicate-runtime abort in homebrew build
esys libs were compiled with llvm clang's -fopenmp (linking .../opt/llvm/lib/libomp.dylib) while their openblas dependency links the standalone 'libomp' formula (.../opt/libomp/lib/libomp.dylib). Loading two different libomp.dylib files in one process triggers "OMP: Error #15 ... already initialized" and an Abort trap: 6 at the first parallel region, so examples crash under plain python3 (run-escript only papered over it with KMP_DUPLICATE_LIB_OK=TRUE). Put the libomp-formula lib dir first in ld_extra so the -lomp added by -fopenmp resolves to the same physical runtime openblas uses, leaving one OpenMP runtime in the process. Paths use HOMEBREW_PREFIX so the fix works on both Apple Silicon (/opt/homebrew) and Intel (/usr/local). Also drop the redundant -lz from ld_extra (zlib is already linked via zlib_libs=['z']) to silence "ld: warning: ignoring duplicate libraries: '-lz'". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b5a51db commit 302b63b

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎scons/templates/homebrew_options.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,22 @@
170170
scotch_libs = ['ptscotch', 'ptscotcherr', 'scotch', 'scotcherr']
171171

172172
# Linker flags - include LLVM libc++ for macOS arm64
173-
ld_extra = ["-L/opt/homebrew/opt/llvm/lib", "-L/opt/homebrew/opt/llvm/lib/c++", "-lz", "-Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++"]
173+
#
174+
# IMPORTANT (macOS OpenMP duplicate-runtime fix):
175+
# Homebrew's openblas links the standalone 'libomp' formula
176+
# (/opt/homebrew/opt/libomp/lib/libomp.dylib), while clang's -fopenmp would
177+
# otherwise pull in LLVM's own copy (/opt/homebrew/opt/llvm/lib/libomp.dylib).
178+
# Loading two different libomp.dylib files in one process triggers
179+
# "OMP: Error #15 ... already initialized" and an Abort trap: 6 at the first
180+
# parallel region. We put the libomp-formula lib dir *first* so that the
181+
# -lomp added by -fopenmp resolves to the same physical libomp that openblas
182+
# uses, leaving exactly one OpenMP runtime in the process.
183+
# Note: zlib is linked via zlib_libs=['z'] above; do not repeat -lz here or the
184+
# linker warns "ignoring duplicate libraries: '-lz'".
185+
ld_extra = ["-L" + HOMEBREW_PREFIX + "/opt/libomp/lib",
186+
"-L" + HOMEBREW_PREFIX + "/opt/llvm/lib", "-L" + HOMEBREW_PREFIX + "/opt/llvm/lib/c++",
187+
"-Wl,-rpath," + HOMEBREW_PREFIX + "/opt/libomp/lib",
188+
"-Wl,-rpath," + HOMEBREW_PREFIX + "/opt/llvm/lib/c++"]
174189

175190
# Optional features
176191
# sympy not available in Homebrew - requires virtual environment installation

0 commit comments

Comments
 (0)