Problems using lcov/gcov for C++ code

I am trying to set up Codecov coverage here: https://github.com/QIICR/dcmqi/pull/272.

I install lcov/gcov with sudo apt-get install lcov.

I set coverage flags to -g -O0 -fprofile-arcs -ftest-coverage.

When I try to run lcov, I get this error below. Has anybody successfully set up and used lcov/gcov for C++ code coverage on CircleCI to give any hints what might be happening here?

ubuntu@box614:~/dcmqi/codecov/dcmqi-build$ lcov --directory . --capture --output-file coverage.lcov
Capturing coverage data from .
Found gcov version: 4.6.4
Scanning . for .gcda files ...
Found 23 data files in .
Processing libsrc/CMakeFiles/dcmqi.dir/__/jsoncpp/jsoncpp.cpp.gcda
Auto-detected compatibility mode for split checksum .gcno file format
/home/ubuntu/dcmqi/codecov/dcmqi-build/libsrc/CMakeFiles/dcmqi.dir/__/jsoncpp/jsoncpp.cpp.gcno:version '409*', prefer '406*'
geninfo: ERROR: GCOV failed for /home/ubuntu/dcmqi/codecov/dcmqi-build/libsrc/CMakeFiles/dcmqi.dir/__/jsoncpp/jsoncpp.cpp.gcda!

The problem was caused by a mismatch in the version of compiler and gcov.

The solution is to use the matching version of gcov while running lcov: --gcov-tool /usr/bin/gcov-4.9

ubuntu@box324:~/dcmqi/codecov/dcmqi-build$ gcc --version
gcc (Ubuntu 4.9.2-0ubuntu1~12.04) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@box324:~/dcmqi/codecov/dcmqi-build$ gcov --version
gcov (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04) 4.6.4
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@box324:~/dcmqi/codecov/dcmqi-build$ /usr/bin/gcov-4.9 --version
gcov (Ubuntu 4.9.2-0ubuntu1~12.04) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.