Last Updated: February 25, 2016
·
1.319K
· mihirpandya

code coverage in C for Mac

gcov is GNU's tool for code coverage. It makes use of graph files (.gcno files) generated when compiled with the -coverage option. However, this option does not exist for Apple's llvm-gcc compiler which means that .gcno files cannot be generated. To solve this, compile exactly the same way but with clang instead of llvm-gcc to generate the graph file. Do something like this:

clang -coverage test.c
./a.out
gcov test.c

You should see the coverage data printed via stdout.