Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active March 9, 2025 01:35
Show Gist options
  • Save scivision/d69faebbc56da9714798087b56de925a to your computer and use it in GitHub Desktop.
Save scivision/d69faebbc56da9714798087b56de925a to your computer and use it in GitHub Desktop.
Xcode 16 Homebrew GCC 14.2 breaks with CMake

With macOS 14.6, 15.0 or 15.3; Xcode 16 breaks with CMake and Homebrew GCC 14.2.

The error is revealed in this simple project.

CXX=g++-14 cmake -Bbuild

cmake --build build

Workaround

The workaround is to specify SDKROOT so that CMake uses the compatible SDK with GCC 14.2, until Homebrew updates its platform environment. Create a file ~/gcc.sh and source ~/gcc.sh to use GCC:

export CC=gcc-14 CXX=g++-14 FC=gfortran-14

export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/

In general in my projects I have CMake print CMAKE_OSX_SYSROOT so when users run into an issue I can help them more quickly.

Configure output

-- The CXX compiler identification is GNU 14.2.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/bin/g++-14 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk

CMake build errors

Lots of build errors if using CMake, starting with:

/opt/homebrew/bin/g++-14   -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -fdiagnostics-color=always -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c d69faebbc56da9714798087b56de925a/main.cpp
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_wchar.h:90,
                 from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h:67,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/cwchar:44,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/bits/postypes.h:40,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/iosfwd:42,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/ios:40,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/ostream:40,
                 from /opt/homebrew/Cellar/gcc/14.2.0/include/c++/14/iostream:41,
                 from d69faebbc56da9714798087b56de925a/main.cpp:1:
/opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:83:8: error: 'FILE' does not name a type
   83 | extern FILE *__stdinp;
      |        ^~~~
/opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:81:1: note: 'FILE' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
   80 | #include <sys/_types/_seek_set.h>
  +++ |+#include <cstdio>
   81 |
/opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:84:8: error: 'FILE' does not name a type
   84 | extern FILE *__stdoutp;
      |        ^~~~
/opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:84:8: note: 'FILE' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
/opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed/stdio.h:85:8: error: 'FILE' does not name a type
   85 | extern FILE *__stderrp;

Regular command line is OK

g++-14 main.cpp -v

works, output ends with

 /opt/homebrew/Cellar/gcc/14.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/14/collect2 -demangle -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ -dynamic -arch arm64 -platform_version macos 15.0.0 0.0 -o a.out -L/opt/homebrew/Cellar/gcc/14.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/14 -L/opt/homebrew/Cellar/gcc/14.2.0/bin/../lib/gcc/current/gcc -L/opt/homebrew/Cellar/gcc/14.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin23/14/../../.. -lemutls_w -lheapt_w /var/folders/dh/k7c2gppn12v3w0plnf_xz94c0000gn/T//ccarxhZd.o -lstdc++ -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/aarch64-apple-darwin23/14 -rpath /opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc -rpath /opt/homebrew/Cellar/gcc/14.2.0/lib/gcc/current
cmake_minimum_required(VERSION 3.20)
project(min LANGUAGES CXX)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
# set OFF if not using C++ modules, or it can trip similar compiler errors due to "-fmodules-ts" flags auto-added when ON.
message(STATUS "CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT}")
foreach(i IN ITEMS OS_NAME OS_VERSION OS_RELEASE OS_PLATFORM)
cmake_host_system_information(RESULT ${i} QUERY ${i})
message(STATUS "${i}: ${${i}}")
endforeach()
add_executable(main main.cpp)
#include <iostream>
int main(){ return 0; }
@benhaub
Copy link

benhaub commented Sep 20, 2024

It broke in the same way for me on gcc@12. This helped me out. Thanks!

@PKua007
Copy link

PKua007 commented Oct 5, 2024

Is there an original issue from Homebrew/GCC somewhere? If so, it would be helpful to link it - I landed here by searching for a general issue, not specifically connected with the scivision project

@saschasc
Copy link

saschasc commented Oct 6, 2024

@PKua007 Most likely this is the current issue on iains gcc-14 branch.
iains/gcc-14-branch#11

Not sure however who will take care to bring this to Homebrew as soon as fixed.

@SeppeStaelens
Copy link

Was stuck on this for hours - the export commands you mentioned resolved it! A million thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment