C++ 代码今天已停止编译(似乎与 iostream 相关)

问题描述 投票:0回答:1

我有一个第三方C++库,它在我的同一台机器上成功编译和链接了至少一年。 除了编译器版本之外,什么都没有改变,但现在编译器给出了这种类型的错误:

[  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 | 

我知道该消息告诉我无法识别

FILE
,因为 stdio.h 或 cstdio 包含文件丢失。 错误信息似乎直接指向文件gdatastream.cpp中的第29行,而第29行只是
#include <iostream>
,我没有改变这一点。但我不明白这一点,因为(a)源代码中没有任何变化,并且(b)
FILE
在源代码中没有出现(但可能在
iostream
标头或其包含的标头之一中出现) .

这让我觉得编译器在更新期间发生了一些变化。 以下是我认为与我的设置相关的内容:

  • 麦克索诺玛 14.7
  • 通过自制软件安装的 Gnu 编译器套件,当前版本为 14.2.0
  • 我使用 cmake 构建系统,这里是 cmake 的输出,以防万一:
-- 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
c++ macos g++
1个回答
0
投票

我也在 macOS 14 上,并且能够通过以下最小示例复制此内容:

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

并通过以下方式编译:

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

我的brew安装的g++默认是MacOS14 SDK,没有这个问题。

include-fixed/stdio.h
文件定义
_STDIO_H_
并继续包含 MacOS SDK 中的
_stdio.h
。这里,SDK 之间的行为有所不同:

  • macOS14:检查
    __STDIO_H_
    (注意:两个下划线)
  • macOS15:检查
    _STDIO_H_
    (一个下划线,与 include-fixed 中的相同)

这使得 GCC 跳过整个

_stdio.h
,其中关键包括
FILE
类型的定义。

这是 GCC 中的一个错误,我认为应该这样报告。

在这个问题得到解决之前,您可以尝试在 CMake 文件中明确将 SDK 版本设置为 14.0,或者像我一样覆盖 MacOS14.sdk 的

-isysroot
参数。

© www.soinside.com 2019 - 2024. All rights reserved.