# Problems using lcov/gcov for C++ code

**URL:** <https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898>\
**Category:** Community\
**Created:** [June 30, 2017, 5:05pm UTC](https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898 "2017-06-30T17:05:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey.fedorov](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/andrey.fedorov/32/10365_2.png) [@andrey.fedorov](https://discuss.circleci.com/u/andrey.fedorov)\
**Post date:** [June 30, 2017, 5:05pm UTC](https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898/1 "2017-06-30T17:05:21Z")

</div>

I am trying to set up Codecov coverage here: [https://github.com/QIICR/dcmqi/pull/272](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?

```auto
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!

```

---

<div class="post-metadata">

**Author:** ![andrey.fedorov](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/andrey.fedorov/32/10365_2.png) [@andrey.fedorov](https://discuss.circleci.com/u/andrey.fedorov)\
**Post date:** [July 3, 2017, 2:37pm UTC](https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898/2 "2017-07-03T14:37:37Z")

</div>

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`

```auto
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.

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:42am UTC](https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898/3 "2018-06-18T11:42:12Z")

</div>

Closed on June 18, 2018, 11:42am UTC


