Hello all,

I'm using gcov (gcc's extension) for code coverage. I wish to use it with g++ (for c++ code). Normally works fine.

The problem arises when i try to use an embedded gcov's function (__gcov_flush()) in order to get coverage data for a running process (non terminating).

Please see the example below:

My sample code looks like this (test.cpp):
Code:
#include <iostream>

using namespace std;

void one(void);
void two(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; }
I compile the program:

Code:
g++ -fprofile-arcs -ftest-coverage test.cpp -o test
and the linker complains:
Code:
test.cpp:(.text+0x1d9): undefined reference to `__gcov_flush()'
collect2: ld returned 1 exit status
Some notes in order to save some time:
1. The c version of this program (with the invocation of the specified function) compiles fine (using gcc)
2. The c++ version of the above program (without the invocation of the specified function) compiles fine (using g++)
3. Placing -lgcov during compilation doesn't work
4. Placing something like:
Code:
extern void __gcov_flush(void);
doesn't work

So i'd like to ask if the operation that i am trying, is valid/supported for g++ and if yes what am i missing?

PS: My system has:
1. SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 2

2. gcov (GCC) 4.1.2 20070115 (SUSE Linux)

TIA
panagiotis