Particael
EN

The compiler: where an MG5_aMC build on Apple silicon breaks

Recorded on 16 October 2026 · Apple-silicon Mac (arm64) · MadGraph5_aMC@NLO 3.5.17 · conda-forge GCC/gfortran 16.2.0 · LHAPDF 6.5.6 · CT18NLO

Its job in the calculation

MG5_aMC writes the calculation as source code (Fortran for the matrix elements and phase-space integration, C++ where it talks to LHAPDF and Pythia 8), and a compiler on your Mac turns that code into the executables that are actually run; MadEvent needs a Fortran 77 compiler and aMC@NLO needs gfortran 4.6 or later. At NLO the compiler must also handle quadruple precision: MG5_aMC checks a failed build for real*16 and real(kind=16) code, and the one-loop library CutTools is built in quadruple precision by default.

Where it breaks, and why

MG5_aMC does not bring a compiler; unless told otherwise it takes the first gfortran on your PATH and, because gcc and g++ on a Mac are Apple's clang, the first clang on your PATH for C++, so the toolchain a process is built with depends on the shell it was launched from. Libraries made by different toolchains then meet in one executable: a process cannot mix arm64 and x86_64 code, and two C++ runtimes in one process ended our Pythia 8 run at exit with Abort trap: 6, after the events had been written. The least visible break is in GCC itself: on macOS its link step passes -no_compact_unwind, and in our test executables linked by gfortran as shipped could not catch a C++ exception that LHAPDF throws and catches internally whenever a PDF set lacks a metadata key MG5_aMC asks for. What you see is libc++abi: terminating due to uncaught exception of type LHAPDF::MetadataError: Metadata for key: AlphaS_Lambda4 not found., then Program received signal SIGABRT, and at the end MG5_aMC reports ZeroDivisionError : float division by zero — it reads like a broken PDF set, and in a 2021 thread on an M1 Mac the same abort, for the key AlphaS_FlavorScheme, was read exactly that way; whether it had the same cause is not established.

What has to match

Our reading of the cases above: every binary in the chain is arm64, all Fortran comes from one gfortran, all C++ that ends up in one process uses one C++ runtime, and the MG5_aMC release is new enough for your gfortran: 3.5.17 is the release whose notes list the fix for compiling NLO processes with gfortran 16.

In Particael

Particael ships the compiler chain inside the app, tested together with MG5_aMC 3.5.17, LHAPDF 6.5.6 and Pythia 8.3. Since version 0.4.0 every release is run for real — at LO, NLO and NLO+PS — on the installed product before it ships.

Notify me

If you build it yourself

Find your error

Search this page for the line on your screen. Paths are shortened with ….

You seeIt meansCauseDo this
libc++abi: terminating due to uncaught exception of type LHAPDF::MetadataError: Metadata for key: AlphaS_Lambda4 not found. then Program received signal SIGABRT then ZeroDivisionError : float division by zeroThe PDF set is fine. A compiled MG5_aMC program aborted while LHAPDF was supplying a default value.The gfortran link step leaves out compact unwind information, and the exception LHAPDF uses internally is not caught.The NLO check below tells you whether your build is affected; the reason is under "Why exceptions die in gfortran-linked programs".
libc++abi: terminating with uncaught exception of type LHAPDF::MetadataError: Metadata for key: AlphaS_FlavorScheme not found.The same kind of abort, for another key.Probably the same as the row above; not established.As above.
Exception : Reported error: End code 134.0A program was killed by SIGABRT (134 = 128 + 6).Look a few lines up for a libc++abi: line.Go to that line in this table.
… Abort trap: 6 ./Pythia8.exe Pythia8.cmd > mcatnlo_run.log 2>&1 at the end of the showerPythia 8 crashed on exit; the events file was still written.Two C++ runtimes in one process: the shower interface was compiled by a different clang than Pythia 8.Set cpp_compiler = /usr/bin/clang and rerun the shower.
No Fortran Compiler detected! Please install oneNo fortran_compiler is configured and MG5_aMC found no gfortran, g77 or f77 on your PATH.No Fortran compiler, or not on this shell's PATH.Put a gfortran on the PATH of the shell you start MG5_aMC from, or set fortran_compiler to its full path.
A fortran compiler (g77 or gfortran) is required to create this output.A build failed and there is no g77 or gfortran on PATH.As above.As above.
Note that MacOSX doesn't have gmake/gfortan install by default. (MG5_aMC's spelling)make itself could not be started.make is not available in this shell.xcode-select --install opens the installer of Apple's Command Line Tools.
error: invalid value 'f95' in '-x f95'Fortran files were handed to Apple's clang.gcc on a Mac is Apple clang, and it was set as the Fortran compiler.Set fortran_compiler to gfortran.
ld: library not found for -lSystemThe linker cannot find macOS's system library.Consistent with a compiler configured for a macOS SDK path that is not there; an MG5_aMC author ties it to the paths of the installed Xcode version.xcode-select --install fixes it "in some case but not always" (MG5_aMC author).
ld: library not found for -lgfortranThe link step cannot find gfortran's runtime library.Not established; in the one public case, libraries had been built with different compilers.Rebuild everything with one compiler.
Undefined symbols for architecture arm64: … "___chkstk_darwin" … ld: symbol(s) not found for architecture arm64Objects built by different toolchains do not fit together.Not established beyond "mixed compilers".Rebuild everything with one compiler.
ld: warning: object file (…) was built for newer macOS version (…) than being linked (10.8)A warning, not an error.MG5_aMC links for an old macOS target (10.7 in 3.5.17 NLO).Nothing; our record calls these warnings harmless, and the run's checks passed.
An x86_64 / arm64 mismatch at link timeOne process cannot mix the two.Part of the chain was built for the other architecture.Check that uname -m prints arm64 in the shell you start MG5_aMC from.
NLO compilation errors with gfortran 16 on an MG5_aMC older than 3.5.17The 3.5.17 release notes list a fix for compiling every NLO process with gfortran 16.virtgranny_red not declared external in genps_fks.f.Use 3.5.17 or later.

Pin both compilers

In input/mg5_configuration.txt:

fortran_compiler = /full/path/to/your/gfortran
cpp_compiler = /usr/bin/clang

MG5_aMC uses a configured compiler when it exists and otherwise falls back to whatever is first on PATH; pinning both removes the dependence on the shell. /usr/bin/clang is the C++ compiler our recorded runs used.

Two checks, with what our record printed

NLO, including the exception test

generate p p > e+ e- [QCD]
output nlo_check
launch

with order=NLO, fixed_order=ON and an LHAPDF set whose info file has no AlphaS_Lambda4 (CT18NLO is one). Before compiling, MG5_aMC names the compilers it will use (INFO: Use Fortran compiler …, INFO: Use c++ compiler /usr/bin/clang). Our recorded run printed, for every subprocess:

INFO:  Result for test_ME: 
INFO:    Passed. 
INFO:  Result for check_poles: 
INFO:    Poles successfully cancel for 20 points over 20 (tolerance=1.0e-05) 

If check_poles aborts with the first line of the table, your build is affected. The first NLO run on a fresh installation also compiles the one-loop libraries once — about nine minutes of an 809-second run in our record; a later full run of the same process took 121 s. The cross section was 2.152 × 10³ ± 7.0 pb for p p > e+ e- [QCD] at the default 13 TeV run card, identical with either C++ compiler.

Shower (NLO+PS)

The same process with shower=PYTHIA8 after install pythia8 inside MG5_aMC. It should end with INFO: Run complete and no Abort trap; our recorded run took 71 s.

If you want to know why

How MG5_aMC picks a compiler. For Fortran it uses the configured fortran_compiler if that program exists, otherwise the first of gfortran, g77, f77 on PATH. For C++ it uses cpp_compiler, otherwise g++ — and if g++ --version says clang and a clang exists on PATH, it uses that clang. On a Mac g++ is Apple's clang, so the C++ compiler is in practice the first clang on your PATH. In our run a conda environment with conda's gfortran package put its own clang in front of Apple's, and the executables were linked against that environment's C++ runtime.

Why exceptions die in gfortran-linked programs. GCC's Darwin driver adds -no_compact_unwind to every link, a workaround for GCC bug 41260 that the source says stays "until the assembler, linker and libunwind are able to deal with the output from GCC"; Homebrew's GCC 16.2.0 keeps it, dropping it only when you link with -fuse-ld=lld. MG5_aMC's executables are linked by gfortran even when they contain C++. In our seven-variant test, every program linked by gfortran as shipped (four of the seven) carried only __eh_frame, no __unwind_info, and aborted on an exception that its own C++ code tried to catch; linked by Apple's driver, or by gfortran without -no_compact_unwind, the same code caught it. Why the missing section stops the catch on arm64 macOS is our reading, not a measurement. LHAPDF throws such an exception every time a key is missing and a default is requested, and MG5_aMC requests AlphaS_Lambda4 with a default — so whether you are hit depends on the PDF set.

Why -lSystem disappears. GCC finds macOS's system libraries in the SDK it was configured with. Homebrew's GCC packages are built on machines with the Command Line Tools and, by Homebrew's own note, do not work out of the box on Xcode-only systems "due to an incorrect sysroot". A missing or moved SDK is consistent with the public -lSystem report; the exact trigger is not established.

Quadruple precision on Apple silicon. In 2021 an MG5_aMC author knew of no gfortran for M1 with quadruple precision and wrote that it "will not work at NLO accuracy". In our 2026 record, the quadruple-precision CutTools library built in the run with conda-forge gfortran 16.2.0 is native arm64, and the NLO checks passed.

What the record covers. conda-forge's gfortran 16.2.0 (30 packages, 143.8 MB, about a minute to install in our run) with MG5_aMC 3.5.17 and LHAPDF 6.5.6 passed the NLO and NLO+PS checks on 16 October 2026; there is no separate LO record for this route, and the macOS version of that run was not recorded. Two things were needed: cpp_compiler = /usr/bin/clang, because the package puts its own clang first on PATH; and a gfortran link step that keeps the unwind information, as described above. Other compiler packages, Homebrew's among them, are not covered by this record.

Sources

  1. MadGraph5_aMC@NLO 3.5.17, INSTALL
  2. MadGraph5_aMC@NLO 3.5.17, madgraph/iolibs/export_v4.py (compiler choice)
  3. MadGraph5_aMC@NLO 3.5.17, Template/NLO/Source/make_opts.inc
  4. MadGraph5_aMC@NLO 3.5.17, Template/Common/Source/PDF/pdf_lhapdf62.cc
  5. MG5_aMC questions on Launchpad, question 706304 (Apple M1, April 2023)
  6. MadGraph5_aMC@NLO 3.5.17, madgraph/various/misc.py (compilation messages)
  7. MG5_aMC questions on Launchpad, question 708878 (Apple M1, January 2024)
  8. Apple Developer, About the Rosetta translation environment
  9. GCC source, gcc/config/darwin.h (DARWIN_NOCOMPACT_UNWIND)
  10. Homebrew, GCC 16.2.0 patch (Patches/gcc/gcc-16.2.0.diff)
  11. LHAPDF 6.5.6, include/LHAPDF/Info.h
  12. MG5_aMC questions on Launchpad, question 698961 (Apple M1, October 2021)
  13. LHAPDF 6.5.6, src/Factories.cc
  14. LHAPDF, Installation
  15. MadGraph5_aMC@NLO 3.5.17, UpdateNotes.txt
  16. bash(1) manual page, exit status of a command ended by a signal
  17. MadGraph5_aMC@NLO 3.5.17, madgraph/interface/madgraph_interface.py (fortran_compiler)
  18. xcode-select(1) manual page, macOS 26.7.1
  19. Homebrew, gcc formula (Formula/g/gcc.rb)

Recorded runs: 16 October 2026, on the versions named at the top of this page.

K-factor