Gcov files gcda and gcno are called object files. You can run gcov from the source directory directly in the object file or use the -o gcov option to specify the object file and the corresponding gcov files.
For example, I have a small project that creates a shared library. I pass the gcov flags to execute the command:
make CFLAGS="-O0 --coverage" LDFLAGS=--coverage
Object files and corresponding gcno files are created in the src/.libs :
$ ls -la src/.libs libtest_la-test.o libtest_la-test.gcno
The source file is in the src folder
$ ls src/ test.c
Next, I run my test suite and gcda files are created:
$ ls -la src/.libs libtest_la-test.o libtest_la-test.gcno libtest_la-test.gcda
Now I can enter the src directory and run gcov , specifying the file name of the object:
$ gcov -o .libs/libtest_la-test.o test.c File 'test.c' Lines executed:27.08% of 96 Creating 'test.c.gcov'
You can also simply run gcov in the object file:
$ gcov .libs/libtest_la-test.o File 'test.c' Lines executed:27.08% of 96 Creating 'test.c.gcov'
Or even just specify the base name of the object file and gcov files:
$ gcov .libs/libtest_la-test File 'test.c' Lines executed:27.08% of 96 Creating 'test.c.gcov'
But I would suggest another automatic approach that works very well for me using lcov . I call it from the top directory, specifying the paths to the source files and object files:
$ lcov --base-directory src --directory src/.libs/ --capture --output-file gcov.info Capturing coverage data from src/.libs/ Found gcov version: 4.8.2 Scanning src/.libs/ for .gcda files ... Found 10 data files in src/.libs/ Processing .libs/test_la-test.gcda […] Finished .info-file creation $ genhtml -o html/coverage gcov.info Reading data file gcov.info Found 10 entries. Found common filename prefix "/usr/src/libtest" Writing .css and .png files. Generating output. Processing file src/test.c […] Writing directory view page. Overall coverage rate: lines......: 56.1% (2098 of 3737 lines) functions..: 68.8% (139 of 202 functions)
The html/coverage directory now contains html files that can be easily parsed in a web browser.
