Alex Rivera | Logout

gcov: cannot open graph file

Asked 2011-07-25T13:26:46.730
19

I am trying to use gcov. I have this simple file a.c:

int main() {
   return 0;
}

So I do

gcc -fprofile-arcs -ftest-coverage a.c -o a
./a
gcov a.c

and I get

a.gcno:cannot open graph file

Am I doing something wrong? I'm under Mac OS X Lion.

Edit
Report

1 Answer

0

I used the following on Mac 10.8.4:

  • Installed via xcode the command line tools:

enter image description here

  • wrote this example code from the gcc website:

    #include <stdio.h>  
    main() 
    {  
       int i, total; total = 0; 
       for (i = 0; i < 10; i++) 
          total += i; 
       if (total != 45) 
          printf ("Failure\n"); 
       else 
          printf ("Success\n"); 
    }
    
  • Compiling using the real GCC gcc-mp-4.7 -fprofile-arcs -ftest-coverage tmp.c

  • And using GCC's gcov: gcov-mp-4.7 -b tmp.c will give you this output:

    File 'tmp.c'
    Lines executed:87.50% of 8
    Branches executed:100.00% of 4
    Taken at least once:75.00% of 4
    Calls executed:50.00% of 2
    Creating 'tmp.c.gcov'
    
answered 2013-06-21T14:28:56.423

Your Answer