C++代码今日突然编译失败(疑似与iostream相关)
GCC更新后第三方C++库编译报错:'FILE' does not name a type
我有一个第三方C++库,在同一台Mac上已经成功编译链接运行了至少一年。期间除了通过Homebrew更新GNU编译器套件到14.2.0版本外,没有修改过任何代码,但现在编译时出现了如下错误:
[ 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 |
我明白报错是因为缺少<stdio.h>或<cstdio>头文件导致FILE类型未被识别,但有两点困惑:
- 源代码完全没有改动过;
- 我的代码里并没有直接使用
FILE,应该是<iostream>或其包含的某个头文件中用到了它。
我推测这是编译器版本更新带来的问题,当前环境配置如下:
- Mac Sonoma 14.7
- Homebrew安装的GCC 14.2.0
- 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
内容的提问来源于stack exchange,提问作者JW1966
相关产品推荐
相关产品推荐

