Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang Code Coverage - Mac OS X - Linker Error

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 I am having trouble in Mac OS X.

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 I am 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

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.

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.

like image 973
KamyFC Avatar asked Oct 10 '13 08:10

KamyFC


2 Answers

I solved this.

I was missing the following Linker Flags

-Wall -fprofile-arcs -ftest-coverage

like image 72
KamyFC Avatar answered Nov 20 '22 08:11

KamyFC


Other Linker Flag -fprofile-arcs fixes the issue for me.

Build Settings > Other Linker Flags > -fprofile-arcs
like image 6
pkamb Avatar answered Nov 20 '22 09:11

pkamb