user1040013
user1040013

Reputation: 21

Unable to generate *.c.gcov file

I have the following structure:

Source_code/build/unix/Makefile
Source_code/code/Lib/src/lib1/a.c

The -fprofile-arcs and -ftest-coverage options are mentioned in the gcc compilation option. It successfully generates the a.gcda and a.gcno files. And when given the following option gcov a.c, it gives the statistics correctly for lines executed.

But it is unable to generate the a.c.gcov file properly, it only contains /* EOF */.

It throws the following messages:

../../code/lib/src/lib1/a.c:creating 'a.c.gcov'
../../code/lib/src/lib1/a.c:cannot open source file

Please let me know to generate the a.c.gcov file.

Upvotes: 2

Views: 2183

Answers (2)

aLt
aLt

Reputation: 48

Running gcov from the folder the code was compiled worked for me.

At the top of the .gcov file it states the complete file path. Ex.:

         -:    0:Source:tmp.c
         -:    0:Graph:tmp.gcno
         -:    0:Data:tmp.gcda
         -:    0:Runs:1
         -:    0:Programs:1
         -:    1:#include <stdio.h>
         -:    2:
         -:    3:int main (void)

If it is in a different folder, i.e, /path/tmp.c, do:

gcov ./path/tmp.c -o ./path/tmp

https://gcc.gnu.org/ml/gcc-help/2010-04/msg00080.html

Upvotes: 1

valbok
valbok

Reputation: 346

In a case when source file cannot be found there is a suggest to use absolute paths within compiling. Instead of using "../".

Secondly, you could try to copy gcno and gcda files to match "../../code/lib/src/lib1/a.c".

Or to fix building rules to make sure that no broken relative paths applied (like ../../)

Upvotes: 0

Related Questions