我想同样的,未定义的参考`__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不工作了。
你有没有在编译时加入'-fprofile-arcs'开关?我认为需要链接库存档。 – Sam
@SAM是的..我已经尝试过。用已经过的方法更新了ans .. –
将-lgcov移动到test.cpp之后。这是一个链接订购问题 – Petesh