'Run gcov tool using c++ compiler
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.
Solution 1:[1]
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).
Solution 2:[2]
link the library gocv
-lgcov
that should help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zoska |
| Solution 2 | kaps |
