Archive for February, 2010

Running Google Test on Snow Leopard, C++ TDD

Thursday, February 25th, 2010

A quick post from a coffee shop in Laos, I’m installing the Google Test framework on my OS X machine to do some TDD C++ work,

I’m using Make, and when I got to the instructions in the README explaining the how to run the sample tests …
### Using GNU Make ###
I ran into a problem ..


myosxmachine:make joe$ make clean && make
rm -f sample1_unittest gtest.a gtest_main.a *.o
g++ -I.. -I../include -g -Wall -Wextra -c ../samples/sample1.cc
g++ -I.. -I../include -g -Wall -Wextra -c ../samples/sample1_unittest.cc
g++ -I.. -I../include -g -Wall -Wextra -c ../src/gtest-all.cc
g++ -I.. -I../include -g -Wall -Wextra -c ../src/gtest_main.cc
ar rv gtest_main.a gtest-all.o gtest_main.o
ar: creating archive gtest_main.a
a - gtest-all.o
a - gtest_main.o
g++ -I.. -I../include -g -Wall -Wextra sample1.o sample1_unittest.o gtest_main.a -o sample1_unittest
ld: in gtest_main.a, archive has no table of contents
collect2: ld returned 1 exit status
make: *** [sample1_unittest] Error 1

Turns out there is an issue with ld and ar on OSX 10.6 .

Adding the ARFLAGS =-q -s to the sample makefile fixes the issue