C++ Code Coverage MAC OSX

I could successfully get code coverage information on our C++ code base on Linux using the GCC features of GCOV and the LCOV tool.

But am having trouble in Mac OSX.

As Apple does not have the classic GCC compiler anymore, and we fear that the LLVM-GCC compiler would one day disappear too (LLVM-GCC is not even available as an option in XCode 5.0) - we have decided to use CLang to compile our code.

While using the CLang compiler iam passing in these flags --> -g -fprofile-arcs -ftest-coverage to generate the Code Coverage information.

I can see the .gcno files getting generated along with the object files.

When it comes to linking - "-lgcov” linker flag which works with GCC is not supported.

The code coverage on Clang / LLVM is now supported by the “profile_rt” library. Unfortunately it’s a bit tricky to find this library because Apple for whatever reason decided not to include it in the default library path. Instead you’ll have to manually navigate to /usr/lib/ to link against it:

And as specified am linking against libprofile_rt.a library.

But i have linker issues.

But i keep getting these linker errors

1
2
3
4
5
6
7
8
9
10
11
Undefined symbols for architecture x86_64:
  "_llvm_gcov_init", referenced from:
      ___llvm_gcov_init in Iso9660Reader.o
      ___llvm_gcov_init in AutoExtractCreator.o
      ___llvm_gcov_init in TempFilePath.o
      ___llvm_gcov_init in TempPath.o
      ___llvm_gcov_init in ReadDirectory.o
      ___llvm_gcov_init in OpenDirectory.o
      ___llvm_gcov_init in SpltPath.o
      ...
ld: symbol(s) not found for architecture x86_64 

I also tried linking against the dynamic library - libprofile_rt.dylib found in /usr/lib folder - But i still get the same issue.

This is CLang Version running on Mountain Lion.

1
2
3
4
5
clang --version
Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
I also have XCode 5.0 and Developer Tools installed

Any replies will be appreciated.

Thanks!!
Topic archived. No new replies allowed.