'GCOV_TAG_COUNTER_ARCS mismatch, got 4294967266, expected 30

I always get this error when I try to run my tests with coverage flags and type gcov <source-file>. This error only happens to the actual source files that the tests call functions from. When I run gcovr -r . it shows 100% coverage for the tests but 0% for the source files even though I know the functions where called because all tests pass. I have done some digging and it seems that this error happens when some functions are not compiled in sync if that makes sense. That one version is older than another. But how can I fix this? This is the command I run to compile the tests:

    ${CC} ${CFLAGS} --coverage -o ./tests/bin/compiled_tests -D TEST ${TEST_SOURCES} ${SOURCES} \
        -I /usr/local/Cellar/criterion/2.3.3/include/ -L/usr/local/Cellar/criterion/2.3.3/lib -lcriterion.3.1.0

The error:

➜ gcov tests/bin/compiled_tests-main.gcno
writeSessionCommandsToGlobalHistoryFile: GCOV_TAG_COUNTER_ARCS mismatch, got 4294967266, expected 30
Invalid .gcda File!
File 'src/main.c'
Lines executed:0.00% of 313
Creating 'main.c.gcov'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source