From dfd017af042b81e732918222df91ae4eb9093379 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 19 Jul 2026 12:24:17 +0000 Subject: [PATCH 22/71] fix(macos): emit NeXT-runtime ObjC (-fnext-runtime) for AppKit interop The app launched then crashed in libobjc prepareForMethodLookup with a nil class (r3=0). Cause: GCC defaults to the GNU Objective-C runtime, but macOS AppKit uses Apple's NeXT runtime; AppKit messaging our GNU-runtime classes finds a mismatched class structure. Compile the ObjC++ sources with -fnext-runtime so GCC emits NeXT/Apple-runtime ObjC that interoperates with the system frameworks. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01AeG2jwYMX5gdvvtUnx3PJa --- src/contour_macos/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/contour_macos/CMakeLists.txt b/src/contour_macos/CMakeLists.txt index 8b0d844b..40bd6489 100644 --- a/src/contour_macos/CMakeLists.txt +++ b/src/contour_macos/CMakeLists.txt @@ -58,6 +58,11 @@ if(APPLE) add_executable(contour ${_app_sources} ${_app_headers}) target_link_libraries(contour PRIVATE contour_macos) target_compile_options(contour PRIVATE ${_contour_macos_warn_opts}) + # GCC defaults to the GNU Objective-C runtime, but macOS AppKit uses Apple's NeXT + # runtime. Without this, AppKit messaging our classes finds a mismatched class + # structure and crashes in the ObjC runtime (nil class in prepareForMethodLookup). + # Emit NeXT-runtime ObjC so our classes interoperate with the system frameworks. + target_compile_options(contour PRIVATE $<$:-fnext-runtime>) # ObjC++ sources need to compile as Objective-C++; .mm is auto-detected, but set the # standard to match the engine (C++23) for the C++ portions they include. set_target_properties(contour PROPERTIES