我也在尝试,
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; }
Run Code Online (Sandbox Code Playgroud)
但对我而言,它给了,
test.cpp:(.text+0x1d9): undefined reference to `__gcov_flush()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
试过以下,
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
Run Code Online (Sandbox Code Playgroud)
我也尝试了上面链接中提到的"-lgcov"和"extern void __gcov_flush(void)".我目前使用的是Ubuntu12.04和g ++ 4.6
所以,我想知道是否有解决方案或gcov_flush不再工作.
void __gcov_flush();
Run Code Online (Sandbox Code Playgroud)
由于代码编译为C++,因此声明存在该名称的C++函数.C++函数受名称修改的影响,因此在(C)链接库中找不到(C++)符号,并且链接器(正确地)抱怨它.
如果声明该函数,则将其声明为具有C链接的函数:
extern "C" void __gcov_flush();
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题.
归档时间: |
|
查看次数: |
5686 次 |
最近记录: |