Build Error: _ffi_type_longdouble symbol not found for arm64 during Python build

Hello Slicer Community,

I am encountering a linker error while building 3D Slicer from source on Apple Silicon. The build fails at approximately 51% during the _freeze_importlib step of the Python internal build.

51%] Linking C executable _freeze_importlib
Undefined symbols for architecture arm64:
“_ffi_type_longdouble”, referenced from:
__ctypes_init_fielddesc in cfield.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
System & Toolchain Information:

  • Machine: Mac Studio (M1/M2/M3 Apple Silicon)

  • OS: macOS 14.x or 15.x (Sequoia/Sonoma)

  • Architecture: arm64

  • Python Version: 3.12.10 (as bundled in the Slicer SuperBuild)

  • CMake Version: 4.2.1

  • Build Generator: Unix Makefiles (attempting to switch to Xcode)

  • LibFFI: Homebrew version 3.5.2 is installed, but the build fails even with Slicer_USE_SYSTEM_LibFFI:BOOL=OFF.

Context: I have attempted to clear the CMakeCache.txt and rebuild with Slicer_USE_SYSTEM_LibFFI set to OFF to force an internal build of LibFFI. However, the linker still seems to be struggling to find the _ffi_type_longdouble symbol required by _ctypes. It appears that the linker might be picking up a system library or a Homebrew version that does not correctly export this symbol for the arm64 architecture.

Question: Has anyone successfully resolved this architectural mismatch on Apple Silicon? Are there specific CMake flags or environment variables I should set to ensure Python links against a compatible version of LibFFI that supports longdouble on ARM64?

Thank you for your help!

Currently macOS arm64 builds are not supported. There are still some remaining items to fix as you discovered. You can however build on an Apple Silicon Mac by building the application as x86_64 and running it using Rosetta 2.

See the following issue and other discourse thread about current state of things:

I looked up longdouble for both ARM64 and x86_64 architectures and what I found is that the actual implementation is hardware, compiler and OS specific. Longdouble can be 80 bits in the calculations padded to 128 bits in memory, or 128 bits, or 64 bits and treated the same as double. I don’t know if all of the scenarios are handled in the build process.

Slicer’s version of libffi needs updating along with other things to support native arm64 builds. For now building on Apple Silicon is possible, but you must build the application as x86_64 instead of arm64.