我想运行通过
brew install gcc
安装的g++-14,这样我就可以使用最新版本的C++,但安装后我在尝试编译代码时遇到很多错误。
所有错误都太长,无法复制到这里,但最后几个是
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/malloc/_malloc_type.h:66:1: error: '__API_UNAVAILABLE3' does not name a type
66 | _MALLOC_TYPE_AVAILABILITY void *malloc_type_zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size, malloc_type_id_t type_id) __result_use_check __alloc_size(3);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/stdlib.h:182:1: error: expected unqualified-id before numeric constant
182 | __API_AVAILABLE(macos(10.0)) __IOS_PROHIBITED
| ^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/stdlib.h:220:56: error: expected initializer before '__API_AVAILABLE2'
220 | int ptsname_r(int fildes, char *buffer, size_t buflen) __API_AVAILABLE(macos(10.13.4), ios(11.3), tvos(11.3), watchos(4.3));
| ^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/stdlib.h:351:9: error: expected initializer before '__API_AVAILABLE2'
351 | __API_AVAILABLE(macos(10.15), ios(13.0), tvos(13.0), watchos(6.0));
| ^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/stdlib.h:359:9: error: expected initializer before '__API_AVAILABLE2'
359 | __API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0), watchos(7.0));
| ^~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/14.1.0/include/c++/14/cstdlib:173:11: error: 'system' has not been declared in '::'
173 | using ::system;
| ^~~~~~
有人问前几个错误是什么。我认为它们在终端中被切断(我无法一直滚动到我编写的
g++-14
命令),但仍然显示的前几个是
/usr/local/Cellar/gcc/14.1.0/lib/gcc/current/gcc/x86_64-apple-darwin23/14/include-fixed/AvailabilityInternal.h:254:13: note: macro "__API_AVAILABLE0" defined here
254 | #define __API_AVAILABLE0(arg0) __API_A(arg0)
| ^~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/pthread.h:358:38: error: macro "__API_AVAILABLE0" passed 2 arguments, but takes just 1
358 | __API_AVAILABLE(macos(10.4), ios(2.0))
| ^
/usr/local/Cellar/gcc/14.1.0/lib/gcc/current/gcc/x86_64-apple-darwin23/14/include-fixed/AvailabilityInternal.h:254:13: note: macro "__API_AVAILABLE0" defined here
254 | #define __API_AVAILABLE0(arg0) __API_A(arg0)
| ^~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/pthread.h:361:38: error: macro "__API_AVAILABLE0" passed 2 arguments, but takes just 1
361 | __API_AVAILABLE(macos(10.4), ios(2.0))
运行
g++-14 --version
输出以下内容
g++-14 (Homebrew GCC 14.1.0) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
编辑:
我认为这会在绝对最小程序上出错,但这似乎是一个问题
#include <iostream>
具体来说这个程序错误:
#include <iostream>
int main() {}
问题已解决。 Apple 对属性使用非标准位置,GCC 不支持。不过,现在可以使用 GCC 14.2 的改编版本,仅解决 macOS 的兼容性问题。 Homebrew 上也提供了更新的软件包。
有关更多详细信息,请参阅此已关闭的 GitHub 问题: https://github.com/iains/gcc-14-branch/issues/12