Building Modern C++ With TDD--Updated Instructions

by Jeff Langr

December 26, 2019

Over the past few years, I’ve received inquiries from folks who were no longer able to build the C++ coding examples in my book, Modern C++ Programming With Test-Driven Development.

My apologies for any difficulties in building the code. Since publication of the book in 2013, Google reconfigured the GoogleTest / GoogleMock projects with a later release. Basically, to fix things, you will simply be updating the locations of include files and library files to reflect these changes.

Modern CPP programming with test driven development

Following are the steps that worked for me (as of this posting) for building and executing the first exercise for Soundex in chapter 2.

git clone
cd googletest
mkdir build
cd build
cmake ..

On my machine, I was situated at my root directory (~) when running these commands.


Scanning dependencies of target gtest
[ 12%] Building CXX object googlemock/gtest/CMakeFiles/gtest.dir/src/
[ 25%] Linking CXX static library ../../lib/libgtest.a
[ 25%] Built target gtest
Scanning dependencies of target gmock
[ 37%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/
[ 50%] Linking CXX static library ../lib/libgmock.a
[ 50%] Built target gmock
Scanning dependencies of target gmock_main
[ 62%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/
[ 75%] Linking CXX static library ../lib/libgmock_main.a
[ 75%] Built target gmock_main
Scanning dependencies of target gtest_main
[ 87%] Building CXX object googlemock/gtest/CMakeFiles/gtest_main.dir/src/
[100%] Linking CXX static library ../../lib/libgtest_main.a
[100%] Built target gtest_main

The lib files exist as:


You will want to create the following export to point to the location of the GoogleTest install. Here is the command I used on my machine:

export GTEST_HOME=/Users/jlangr/googletest

You can create the chapter 2 Soundex project by doing a pull from GitHub:

git clone

Then navigate into that directory:

cd c2

Change the CMakeLists.txt file. The include_directories and link_directories will need to change to the following:

include_directories($ENV{GTEST_HOME}/googlemock/include $ENV{GTEST_HOME}/googletest/include)

This is the key step to getting things building! Please pay careful attention when making these changes.

The rest of the instructions are generally the same. I used the following:

mkdir build
cd build
cmake ..

Note that your files will not compile for the first example… the book directs you to then create the Soundex source code.

Share your comment

Jeff Langr

About the Author

Jeff Langr has been building software for 40 years and writing about it heavily for 20. You can find out more about Jeff, learn from the many helpful articles and books he's written, or read one of his 1000+ combined blog (including Agile in a Flash) and public posts.