我有一个要配置的程序。但是,它具有一些使用属性gnu_inline声明的函数。如果尝试使用-finstrument-functions标志构建程序,则会出现链接器错误,例如:

#define always_inline __attribute__((always_inline, gnu_inline))
static int inline always_inline f()
{
    return 0;
}

int main(int argc, char *argv[])
{
    int i = f();

    return i;
}


给我“对f()的未定义引用”错误。
问题在于,编译器尝试将f()的地址传递给性能分析函数,但是该函数是内联的,因此没有函数体,也没有f()的地址。

我尝试使用-fkeep-inline-functions标志构建程序,但是它显然对用gnu_inline声明的函数没有影响。

是否有可能以某种方式强制编译器为链接器制作f()的单独副本?还是这些功能无法分析?

我的程序使用Qt 5,并且这些函数位于Qt标头中,因此,如果可能的话,我不希望更改函数声明。

最佳答案

至少,即使可能存在更漂亮的解决方案,以下两个选项也可以使您的方案正常工作:


  -finstrument-functions-exclude-file-list =文件,文件,...
  
  设置排除在仪器之外的功能列表(请参见“ -finstrument-functions”的说明)。如果包含函数定义的文件与一个匹配
             的文件,则未检测到该功能。匹配是在子字符串上完成的:如果file参数是文件名的子字符串,则认为它是匹配项。


       For example:

               -finstrument-functions-exclude-file-list=/bits/stl,include/sys

       excludes any inline function defined in files whose pathnames contain "/bits/stl" or "include/sys".

       If, for some reason, you want to include letter ',' in one of sym, write ','. For example, "-finstrument-functions-exclude-file-list=',,tmp'" (note the single quote surrounding the
       option).



  -finstrument-functions-exclude-function-list = sym,sym,...
  
  这类似于“ -finstrument-functions-exclude-file-list”,但是此选项设置要从检测中排除的功能名称列表。要匹配的功能名称是其用户可见的名称,例如“ vector blah(const vector&)”,而不是内部错误的名称(例如“ _Z4blahRSt6vectorIiSaIiEE”)。匹配是在子字符串上完成的:如果sym参数是函数名称的子字符串,则认为它是匹配项。对于C99和C ++扩展标识符,函数名称必须以UTF-8给出,而不是使用通用字符名称

关于c++ - 用mingw 4.8强制复制gnu_inline函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20912359/

10-11 22:07
查看更多