Saturday, October 22, 2016

Installing gcc on an oldish OSX so I can get code coverage to work

On one my computers that I am using, it is running OSX 10.8.5, this is known as Mountain Lion. On this computer, I want to install the gcc on it, but I have some difficulties in find the right instructions.

The default gcc that is install is an alias to

localhost:bin tehnyitchin$ ll gcc*
lrwxr-xr-x  1 root  wheel  12 Aug 18  2013 gcc -> llvm-gcc-4.2


So it is not really running the real gcc that you can get from GNU. Scouring the internet, I came across these instructions at Helsinki University Geodynamic Group.

https://wiki.helsinki.fi/display/HUGG/Install+for+older+versions+of+Mac+OS+X

I am working on this as I want to get code coverage working. It is not working at all with the default llvm-gcc-4.2. Compiling the code with a --coverage causes nothing to occur. 

Typically, when the code is compiled with --coverage, the .gcno file is also generated. gcov uses this file as part of its code coverage measurements. If I enable the -v option to increase its verbosity, I can see that it is linking the gcov library, but I am not sure if it is actually doing it.

This question on Stack Overflow shows that the code coverage on my OSX is not working.
http://stackoverflow.com/questions/8622293/no-code-coverage-with-mac-os-x-lion-and-xcode-4-llvm-g-4-2

As I execute a simple main.c, I am not getting the correct .gcno. However, when I switch it from gcc to clang, the .gcno files are generated.

Back to the story, After downloading xcode-4 as per the instruction from Helsinki, it failed to installed due to some unknown reason. The logs did not show anything obvious. I did not continue with installation as clang was generating the code coverage files for me. My feeling is that Apple has built llvm-gcc-4.2 without code coverage support. To overcome this, the real gcc is needed. Luckily, in my case, clang came to the rescue.


I am writing a Guide to Successful Unit Tests, you can get it here at Leanpub. 

No comments:

Post a Comment