0

I have 3 files in a folder. one.cpp, one.hpp and main.cpp. one.hpp has a class declaration. one.cpp has definition of functions in the class both under same namespace.Iam calling a function from the class in main and including one.hpp in main. how can compile and run all these files to generate coverage using gcov ?

I tried generating seperate object files and creating an executable .Didn't work

Weather Vane
  • 33,872
  • 7
  • 36
  • 56
Cod3r
  • 17
  • 5
  • The simplest way to build the program would be `g++ -I. main.cpp one.cpp`. That will name the resulting program `a.out`, but you can specify a different name via a `-o` option. I forget what option(s) you need to add to enable gcov tooling -- look it up in the manual. – John Bollinger Jun 22 '21 at 10:49
  • If you enable code coverage in your compiler it will automatically generate gcno files for each object file. If you run an executable that was compiled with code coverage it will generate gcda files during execution (matching the gcdo files). gcda + gcno will be used to generate your report. You don't actually check you source files but your object files. – Simon Kraemer Jun 22 '21 at 10:58
  • Did you read the manual? https://gcc.gnu.org/onlinedocs/gcc/Gcov.html#Gcov – Simon Kraemer Jun 22 '21 at 11:00
  • Johns suggestion worked with some gcov specific modifications. – Cod3r Jun 22 '21 at 13:05

1 Answers1

0

Compiled code using g++ -I. main.cpp one.cpp as John Suggested. To get coverage object after compilation and execution Modified the line as g++ --coverage -I. main.cpp one.cpp.It generated a.out and required .gcna and .gcda files.Generated coverage report as i wanted.Thanks for the help.

Cod3r
  • 17
  • 5