Intel 代码覆盖率 -> 对 `std::string::_S_compare(unsigned long, unsigned long) 的未定义引用

Intel code coverage -> undefined reference to `std::string::_S_compare(unsigned long, unsigned long)

我使用带有标志 -prof-gen:srcpos 的英特尔编译器 icc/icpc 在 Redhat 6 下编译代码以执行代码覆盖率分析。这对我的代码的某些部分工作正常,但我在一些库中遇到问题。

我收到错误

    undefined reference to std::string::_S_compare(unsigned long, unsigned long)

我 link 反对 /usr/lib64/libstdc++.so.6.0.13.

不幸的是,我无法区分可以编译的代码和不能编译的代码之间的区别。一个不编译的库是静态构建和 linked。

此致,格奥尔格

我使用的是 intel 编译器版本 15.0.3 20150407 和 4.4.7 20120313 (Red Hat 4.4.7-17)。

更新到 gcc 4.8.2 20140120 后,它工作正常。在旧的 gcc 版本中,没有提供所需的功能。

我一直在为同样的错误而苦苦挣扎。下面是一个修复程序,能够在 RHEL5 和 RHEL6 上编译相同的代码,并且不会出现您在生成 Intel 覆盖率报告时列出的错误。只需将此代码段放在编译器抱怨缺少符号的 .cpp 文件中即可。

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// NOTE: The block below is ONLY needed for building with the
//       Intel code-coverage flags turned on. For some reason,
//       this comes up as an un-resolved symbol. So, for CODE
//       COVERAGE BUILDS ONLY, this symbol is defined here.

#if defined __INTEL_CODE_COVERAGE__ && defined __GLIBC__

// Specify that 2.6 is required because we know that 2.5 does NOT need this.
// The macro tests for >=. Will need to tune this if other glibc versions are in use.
// We have RHEL5 using 2.5, RHEL6 using 2.12.

#if __GLIBC_PREREQ(2,6) 

namespace std {
    template int string::_S_compare(size_type, size_type);
}

#endif /* glibc version >= 2.6 */

#endif /* intel code coverage and using glibc */

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////