c++macosg++

C++ Code Has Stopped Compiling Today (Appears Related to iostream)


I have a third-party C++ library that has successfully compiled and linked on my same machine for at least a year. Nothing has changed except possibly the compiler version, but now the compiler is giving errors of this type:

[  2%] Building CXX object GEMS3K/CMakeFiles/GEMS3K_OBJECT.dir/gdatastream.cpp.o
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/usr/include/_wchar.h:90,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.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 /Users/jwbullard/Documents/Projects/Modeling/THAMES/src/GEMS3K-standalone/GEMS3K/gdatastream.cpp:29:
/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 | 

I understand that the message is telling me that FILE is not recognized because the stdio.h or cstdio include file is missing. The error message seems to point directly to line 29 in the file gdatastream.cpp, and line 29 is just #include <iostream>, and I haven't changed that. But I don't understand this because (a) nothing has changed in the source code, and (b) FILE appears nowhere in the source code (but probably does somewhere in the iostream header or one of the headers it includes.

This makes me think that something has changed with the compiler during an update. Here is what I think is relevant about my setup:

-- The CXX compiler identification is GNU 14.2.0
-- The C 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++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/homebrew/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Setting build type to 'Release' as none was specified.
-- Building json <-> key-value converter
-- Configuring done (6.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/xxx/Documents/Projects/Modeling/THAMES/src/GEMS3K-standalone/build

Solution

  • I am also on macOS 14 and was able to replicate this with the following minimal example:

    #include <stdio.h>
    int main(){}
    

    and compiling it through:

    g++-14 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk foo.cpp
    

    My brew-installed g++ defaults to the MacOS14 SDK, which does not have this problem.

    The include-fixed/stdio.h file defines _STDIO_H_ and proceeds to include _stdio.h from the MacOS SDK. Here, the behavior differs between SDKs:

    This makes GCC skip the entire _stdio.h, which crucially includes the definition of the FILE type.

    This is a bug in GCC and should be reported as such, I think.

    Until this gets fixed you could try setting the SDK version to 14.0 explicitly in your CMake file or by overriding the -isysroot argument to MacOS14.sdk like I did.