5

I want to generate the coverage reports using gcov and lcov.

What I have done till now:-

1. I compiled my code using --fprofile-arcs and -fprofile-coverage in
g++.

2. I have linked using lcov.

3. I have .gcno files with th e.o location.

4. When I execute binary, it is resulting into .gcda files.

What I have to do :-

I have to use these data files (.gcda) and want to create a clean report using lcov.

Problem :-

There are multiple directories in which there are source files and inside each directory I am creating an obj/ARCH dir to keep the object files.

Hence the final directory structure would be:-

  proto  ----> MJ1 ----> MJ2 ----> MJ3 ----> MJ4 ----> MJ5

  MJ1 ----> .cpp 

      ----> obj/linux/*.o *.gcno *.gcda 

  MJ2 ----> .cpp 

      ----> obj/linux/*.o *.gcno *.gcda 

same with M3, M4, M5.

I am executing lcov from the proto level and it finds .gcda files but giving some error in finding .h and .C file. Any idea how to make this process path independent?

Error:-
../MjUtil/glob.h:cannot open source file
../MjUtil/MJError.h:cannot open source file
../MjUtil/OsStatisticsFile.h:cannot open source file

Thanks in advance.

crazy_prog
  • 1,085
  • 5
  • 19
  • 34

3 Answers3

2

Have you tried supplying the --base-directory . option to lcov ?

Bulletmagnet
  • 5,665
  • 2
  • 26
  • 56
1

Usually it is good idea to try absolute paths when you compile CPPs.

Also it should not depend on what dir you run lcov. For example:

lcov -c -d ../../../src -o lcov.info

And src dir contains:

main.cpp main.gcno main.gcda

Even if main.gcno file comprises relative path to main.cpp, lcov will handle it.

You also should make sure that gcda/gcno files were not moved. By script or manually. In case if they have been moved, of course relative paths will be incorrect and lcov will not be able to find sources.

valbok
  • 321
  • 2
  • 5
1

You can pass the --directory flag multiple times, lcov will parse each one sequentially.

cmannett85
  • 21,725
  • 8
  • 76
  • 119