small medium large xlarge

18 Mar 2014, 09:01
Bopamo Osaisai (1 post)


I am very new to TDD and this great book. I am in the process of working out the exercises in CH 2.7. When I run the command:

make -f

I get the following output and associated error:

Linking BookCode_Unity_tests
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [BookCode_Unity_tests] Error 1

Thus far I know I am getting this error because Xcode now uses llvm and not gcc. However, I am not sure what the best approach is to resolving it. Can someone please help me with this? Thank you very much in advance!

Best regards,


Trekkie profile pic_pragsmall
23 May 2014, 21:02
toby carter (6 posts)

This response is probably too late for you, but it may help other people coming here for help. I know it certainly would have helped me out a few days ago ;)

As indicated above, recent versions of OSX use a new compiler called clang, and the gcc command is set up to use this instead. cheeky apple. It is possible to install gcc alongside it however. Both Homebrew & MacPorts offer packages, but I found that Homebrew seemed to get in some permanent loop whilst installing, so I ended up using MacPorts which you can install from

With MacPorts installed from that site, first you need to install the correct version of gcc. Currently they’re at 4.9 but neither the sample code or the CppUTest source will compile with that. Through trial & error (mosely error) I found that 4.6 works. In a terminal session type “sudo port install gcc46” This’ll set up gcc on your machine, however, gcc will still be pointing to clang. Macports then lets us choose between different versions of installed software. Typing “port select –list gcc” will show you the different versions installed. When it is set to “none” it’ll default to using clang as before, but you can set it to whichever other versions you have installed thusly “sudo port select –set gcc mp-gcc46” changing that mp-gcc46 bit at the end to other installed versions or back to none will set gcc to point at them, so you can flip around different compilers based on what you’re working on.

After running this command you’ll need to exit terminal and reopen it for it all to get pointed in the right direction. Whereupon “gcc –version” should happily start reporting that v4.6 is installed. That got both the book code and the CppUTest source to compile correctly for me.

16 Jun 2015, 09:24
Thopaz (1 post)

Just a quick note. Toby Carters hint works, but: Note that the commands should be
port select --list gcc
sudo port select --set gcc mp-gcc46
So double minus before list or set in order to work. =)

04 Jul 2015, 16:49
Arnd R.Strube (88 posts)

If memory serves me right, you don’t have to explicitly link gcov. It would probably build correctly if you took out -lgcov. Might need a bit of digging to find where it is set in the Makefile.

You must be logged in to comment