我想同樣的,未定義的參考`__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