1

I am compiling all my .cpp with -g --coverage and linking with --coverage

When I run my executable, the .gcda file is produced.

But when I do gcov file_test.cpp it says:

$ gcov file_test.cpp
file_test.gcno:cannot open notes file
file_test.gcda:cannot open data file, assuming not executed
No executable lines

But the directory contains all the required files

$ ls
file_test.cpp  file_test.cpp.gcda  file_test.cpp.gcno  file_test.cpp.o

If you look at the gcov error, it looks like it's chopping off the .cpp from the filename.

What is happening?

If it's relevant, I'm using cmake and the .gcda, .gcno files are produced next to the .o file which is in cmake's nested folder structure so I have to copy file_test.cpp to that folder and run gcov.

Bob
  • 4,576
  • 7
  • 39
  • 107
  • I use `clang` and `llvm-cov`. Regardless... `clang++ -std=c++17 -O0 -g -fprofile-instr-generate -fcoverage-mapping foo.test.cpp foo.cpp -o foo`, then `LLVM_PROFILE_FILE=foo.profraw ./foo`, then `llvm-profdata merge -sparse ./foo.profraw -o foo.profdata`, then `llvm-cov show -format=html -tab-size=4 ./foo -instr-profile=foo.profdata foo.cpp > foo.html`, then (for pretty-fying) `echo '' >> foo.html`, and finally `open foo.html`. If your unit tests don't have **coverage**, you've got bubkes. – Eljay Jun 07 '23 at 21:57
  • @Eljay I compiled all my files with `—coverage`; I checked the build log. The fact that I got `.gcno` for this file during compilation AND `.gcda` was generated when it ran means my compile and link options are correct. – Bob Jun 08 '23 at 00:27

0 Answers0