对"__gcov_flush"的未定义引用
undefined reference to `__gcov_flush'
我正在尝试同样的事情,
http://www.linuxforums.org/forum/suse-linux/135465-gcov-g.html
来自链接的代码,
#include <iostream>
using namespace std;
void one(void);
void two(void);
void __gcov_flush(void);
int main(void)
{
int i;
while(true)
{
__gcov_flush();
cout << "Enter a number(1-2), 0 to exit " << endl;
cin >> i;
if ( i == 1 )
one();
else if ( i == 2 )
two();
else if ( i == 0 )
break;
else
continue;
}
return 0;
}
void one(void)
{ cout << "One is called" << endl; }
void two(void)
{ cout << "Two is called" << endl; }
但对我来说,它也给了,
test.cpp:(.text+0x1d9): undefined reference to `__gcov_flush()'
collect2: ld returned 1 exit status
尝试了以下方法,
g++ -fprofile-arcs test.cpp
g++ -fprofile-arcs -g test.cpp
g++ -fprofile-arcs -ftest-coverage -g test.cpp
g++ -fprofile-arcs -ftest-coverage -g test.cpp -lgcov
我也尝试了上面链接中提到的"-lgcov"和"extern void __gcov_flush(void)"。我目前使用的是 Ubuntu12.04 和 g++ 4.6
所以,我想知道是否有解决方案,或者gcov_flush不再有效。
void __gcov_flush();
由于代码被编译为C++,因此声明存在该名称的C++函数。C++函数受名称重整的影响,因此在 (C) 链接库中找不到 (C++) 符号,链接器(理所当然地)抱怨它。
如果声明函数,请将其声明为具有 C 链接的函数:
extern "C" void __gcov_flush();
这应该可以解决问题。
<小时 />请注意 Paweł Bylica 的评论 - __gcov_flush()
已在 GCC 11 中删除,您应该使用 __gcov_dump()
。
我修复了更改设置的此问题。
测试项目 --> 生成设置
仪器程序流程 = 是
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用