14

我今天从我认为具有 g++-4.6 的 Ubuntu 12.04 升级到具有 g++-4.7.2 的 Ubuntu 12.10。在我的代码中,我有几个函数标记为__attribute__((always_inline)). 原因很简单,分析向我展示了它显着提高了代码的性能。它适用于 g++ 4.6,但现在使用 g++ 4.7 我收到错误消息:

错误:调用 always_inline 'void func_name(args)' 时内联失败:函数体可以在链接时被覆盖

我无法分享我的实际代码,我试图缩小范围,但是当我更改太多时,错误就会消失,所以这没有帮助。我对此错误消息的根本原因感兴趣。

4

2 回答 2

19

我无意自己回答这个问题,但我在发布后几分钟意外找到了答案。

此(神秘)错误消息的原因是该函数未标记为inline,仅__attribute((always_inline))

于 2012-11-20T11:45:37.253 回答
0

For us, the issue was that we failed to also declare the function "static". "attribute((always_inline))" means, in plain text, "inline this and never include a function body" and the error message means "the compiler had to include a function body". In our case, since the function wasn't "static", it needed to be available for an external reference.

于 2019-10-09T22:06:08.740 回答