G++ 在使用 extern inline 时出现 "storage class specified" 错误

G++ issues "storage class specified" errors when using extern inline

我使用link-time优化(-fltog++ld命令行)和我的一些方法声明(在headers)被标记作为 extern inline(并且只是 .cpp 文件中的 inline)。编译产量:

./Client/include/GVGLObjects.hpp:96:32: error: storage class specified for 'VertexBuffer'
             EFAST VertexBuffer();
                                ^

以及其他方法和函数的一系列类似错误。 EFAST 表示 extern inline.

为什么在启用 LTO 的情况下会发生这种情况?如果不允许,我如何将声明和定义与内联和 LTO 分开?

extern inline 存在于 C 中,而不存在于 C++ 中,尽管许多编译器允许它作为扩展 (ref)。

大概是 GCC 用于执行 LTO 的任何机制和文件格式() is not compatible with this non-standard thing. The documentation for -flive-patching=level 很有趣,因为它描述了与内联和存储相关的内容 类,并告诉我们其中一些内容不可用使用 LTO 时(尽管实际的 -flto 描述并未明确指出 extern inline 扩展名)。

您可能不希望在 C++ 代码中使用此 EFAST 宏。