3

I am working, for the first time, with the coverage tool gcov to analyze a large project. I have a directories structure like this:

    HW
     -FooHW1.cpp
     -FooHW1.h
     -FooHW2.cpp
     -FooHW2.h
     -...
     -Makefile.am
    Lib1
     -FooLib1.cpp
     -FooLib1.h
     -FooLib2.cpp
     -FooLib2.h
     -...
     -Makefile.am

    Lib2
     ...
     -Makefile.am
    Lib3
     ...
     -Makefile.am
    Main
     -main.cpp
     -main.h
     -Makefile.am

Each directory has its own Makefile generated using automake to generates dependecies and whatsoever where the compiler used is c++.

Since my objective is the analyses of the statement coverage I tried to use gcov adding the following lines to each Makefile.am to generate my .gcno and .gcda files in order to use gcov:

    AM_CXXFLAGS = -fprofile-arcs -ftest-coverage
    AM_LDFLAGS = -fprofile-arcs

Unfortunately even if it compiles it doesn't create (or link) the several *.o and when invoking gcov it usually gives me the error:

    undefined __gcov_init

I also tried susbtituing, according to http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#index-coverage-536, the upper instructions to:

    AM_CXXFLAGS = --coverage
    AM_LDFLAGS = --coverage

but it doesn't do the trick for me.

I would like to specify that this is the first experience with the gcov tool and in dealing with large c++ projects. Thaks for your help.

gRomano
  • 37
  • 1
  • 2
  • 4

2 Answers2

0

http://bobah.net/d4d/tools/code-coverage-with-gcov and http://www.slideshare.net/maguschen/using-gcov-and-lcov are good sources for using gcov/lcov (with this help I've managed to use lcov in really big, complicated project)

lcov gives you possibility to show results of coverage in html format (nice percentages for listed files or even for lines in source files).

Oh, and I hope you do realize it's a dynamical coverage, so you have to actually run the program to get any coverage (building should only create .gcno files).

zoska
  • 1,684
  • 11
  • 23
  • thanks, I know i have to run it in order to get my coverage(that's actually the objective of my project in order to test some module of a mobile robot)! took a look on the lcov output and it's actually much nicer and comprehensible than the gcov one so i'll try to use it once i'll be able to make it work, the only difference should be when invoking it, am i right? `lcov ` instead of `gcov` Thanks! – gRomano Aug 05 '13 at 15:28
  • The first link http://bobah.net/d4d/tools/code-coverage-with-gcov is 404 now. – Qi Luo Aug 02 '21 at 03:57
  • Latest archive: https://web.archive.org/web/20171013210930/bobah.net/d4d/tools/code-coverage-with-gcov – hlovdal Jan 29 '22 at 20:17
-1

link the library gocv

-lgcov

that should help

kaps
  • 186
  • 4
  • 18