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.

Thank you @jamesobutler for the clarification regarding the current state of macOS arm64 support.
Based on the guidance, I am building 3D Slicer as x86_64 on Apple Silicon and running it under Rosetta 2.

I am working on a custom 3D Slicer application, and below are the exact commands and configuration I am using, followed by the errors I am encountering.


:hammer_and_wrench: Build environment

  • macOS: 14.x (Apple Silicon, Mac Studio)

  • Architecture: x86_64 (Rosetta 2)

  • Xcode: Installed from /Applications/Xcode.app

  • Qt: 5.15.2 (clang_64)

  • CMake: system-installed

  • Custom Slicer build


:receipt: CMake configuration used

cd ~/Slicer-Build

# Clean previous build
rm -rf Slicer-build

cmake \
  -DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
  -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=14.0 \
  -DCMAKE_OSX_SYSROOT:PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
  -DCMAKE_BUILD_TYPE:STRING=Release \
  -DQt5_DIR:PATH=/opt/Qt/5.15.2/clang_64/lib/cmake/Qt5 \
  -DSlicer_USE_SYSTEM_QT:BOOL=ON \
  -DSlicer_USE_SimpleITK:BOOL=OFF \
  -DSlicer_USE_PYTHONQT:BOOL=OFF \
  -DSlicer_USE_PYTHON:BOOL=ON \
  -S ~/Slicer-Source \
  -B .


:building_construction: Build command

cmake --build . -j4 2>&1 | tee build.log

When attempting to build Python explicitly:

cmake --build . --target python -j4 2>&1 | tee python-build.log


:cross_mark: Build errors encountered

During the build, I encounter the following error related to Python headers:

/Users/archiwizstudio/Slicer-Source/Base/QTCore/qSlicerCoreApplication.cxx:1216:8:
error: unknown type name 'Py_ssize_t'; did you mean 'ssize_t'?

Additional output:

[ 47%] Built target qMRMLWidgets
make[3]: *** [all] Error 2
make[2]: *** [Slicer-prefix/src/Slicer-stamp/Slicer-build] Error 2
make[1]: *** [CMakeFiles/Slicer.dir/all] Error 2
make: *** [all] Error 2

Attempting to build the Python target directly results in:

make: *** No rule to make target `python'.  Stop.


:magnifying_glass_tilted_left: CMake cache confirmation

grep -i "Slicer_USE_PYTHON" CMakeCache.txt

Output:

Slicer_USE_PYTHON:BOOL=ON
Slicer_USE_PYTHONQT:BOOL=OFF

No Python include or library paths appear to be populated:

grep -i "PYTHON" CMakeCache.txt | grep -i "DIR\|INCLUDE\|LIBRARY"


:red_question_mark: Questions

  1. Is this Python error (Py_ssize_t not found) expected when using system Python with Slicer_USE_PYTHON=ON?

  2. Is it required to use Slicer SuperBuild–provided Python instead of system Python on macOS?

  3. Are there recommended Python versions (e.g., 3.9 / 3.10) known to work reliably for x86_64 Rosetta builds?

  4. Does this configuration depend on a specific Xcode version for successful Python integration?

Any guidance or recommended build scripts for resolving Python-related build issues on Apple Silicon (x86_64 via Rosetta) would be greatly appreciated.
this is the systmem information
System

OS: macOS 26.2
Build: 25C56
Kernel: Darwin 25.2.0
Machine Architecture: arm64
Rosetta Translation: NO (sysctl.proc_translated = 0)

Xcode

Xcode Version: 26.2
Xcode Build: 17C52
Xcode Path: /Applications/Xcode.app/Contents/Developer
macOS SDK: MacOSX26.2.sdk
SDK Version: 26.2

Compiler

Compiler: Apple clang
Version: 17.0.0 (clang-1700.6.3.2)
Target: arm64-apple-darwin25.2.0
clang Binary: Universal (x86_64 + arm64e)

Build Tools

CMake Version: 4.2.1
CMake Provider: Kitware
Make Version: GNU Make 3.81
Make Binary: Universal (x86_64 + arm64e)
Ninja Version: 1.13.2
Ninja Binary: arm64 (/opt/local/bin/ninja)

Qt

Qt Version: 5.15.2
QMake Version: 3.1
Qt Path: /opt/Qt/5.15.2/clang_64
Qt Architecture: x86_64
Qt5Core: /opt/Qt/5.15.2/clang_64/lib/libQt5Core.dylib

Python

python: not found
python3 Version: 3.14.2
python3 Path: /opt/homebrew/bin/python3
Python Architecture: arm64

Git

Git Version: (not reported)
Repository: Slicer (custom build)

Slicer Configuration (relevant flags)

Slicer_USE_PYTHON: ON
Slicer_USE_PYTHONQT: OFF
Slicer_USE_SYSTEM_QT: ON

Thank you for your help.

As a first try you should let the Slicer super build build all the dependencies it wants including the python version which becomes an embedded python in the application. It will have to build an x86_64 python for use in this x86_64 application.

The following linked post was a good one that helped me build an x86_64 build on arm mac successfully.

The Slicer factory build machine builds successfully on macOS with the following environment:

This is unlikely to work:

-DSlicer_USE_PYTHONQT:BOOL=OFF \

I doubt that path is ever tested since PythonQt is pretty central to most Slicer use cases.

Hello @jamesobutler @pieper

I’m trying to build 3D Slicer on macOS (x86_64) using Xcode 16.1 and the macOS 15 SDK, and I’m currently facing linker errors related to Qt during the VTK build stage.

At the moment, I do not have Qt built from source, as I couldn’t find an easily available source/build setup for macOS. I am currently using Qt 5 from Homebrew (brew install qt@5).

Since I am new to macOS development, I’m not sure whether using Homebrew’s Qt5 is appropriate for building 3D Slicer, or if this could be the cause of the Qt symbol/linker issues I’m seeing.

Questions:

  1. Is Homebrew Qt5 (qt@5) supported or recommended for building 3D Slicer on macOS?

  2. If not, what is the recommended way to obtain Qt 5.15.2 for macOS (prebuilt binaries or building from source)?

  3. For those who have successfully built Slicer on macOS, could you please share:

    • The Qt version used

    • The Xcode version

    • The exact CMake configuration / build command used by you or by Kitware?

  4. Are there any known compatibility issues between Qt 5.15.x and Xcode 16.x / macOS 15 SDK?

Any guidance, commands, or references would be very helpful, especially from someone who has already completed a successful macOS build.

Thank you very much for your help.

Best regards,
Salim Ullah

I haven’t built from source on a mac recently, and when I tried to rebuild a previous build with the current Slicer source there were errors (I don’t recall the specifics). So I suspect with the ongoing changes in the OS, xcode, cmake, python, homebrew, and Slicer source it’s possible that there is no currently working build formula for any particular machine. I know that the script below did work, maybe a year ago with whatever OS and xcode were current at the time.

BUILD_TYPE=Debug
#BUILD_TYPE=Release

CMAKE=/Users/pieper/Downloads/cmake-3.31.7-macos10.10-universal/CMake.app/Contents/bin/cmake

${CMAKE} \
	-DSlicer_VTK_VERSION_MAJOR:STRING=9 \
	-DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE} \
	-DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 \
	-DQt5_VERSION:STRING=5.15 \
	-DQt5_DIR:PATH=/usr/local/Cellar/qt@5/5.15.17/lib/cmake/Qt5 \
	/Users/pieper/slicer/latest/Slicer

Personally I’ve been waiting for things to settle down before trying to build again. It would be great if you can work through and get a working combination.