Resources: Programming in C++

Installing GoogleTest (Unit Test Framework for C++)

Ubuntu-like Linux (including Windows Subsystem for Linux)

Use apt to install the correct packages

sudo apt update
sudo apt install libgtest-dev

YOU ARE DONE. DON’T DO ANYTHING ELSE.

Mac OS X, or other OS from source code (at a Unix prompt)

These instructions are only for people with Mac OS X, or people who want to do more work and install from source code on Linux. If you did the sudo apt installation above, do not do these steps.

Visit the release page. Download the latest release (choose zip or tar.gz). This is currently 1.10.0 (Fall 2020). In the instructions below, replace 1.10.x with the current release of google test.

Unpack the source code. You must run this command in the directory where the archive file was downloaded.

unzip googletest-1.10.x.zip
or 
tar -zxf googletest-1.10.x.tar.gz

Move into the source tree:

cd googletest-1.10.x/googletest

Compile the source code, and build a library:

g++ -std=c++11 -pthread -g -Wall -Wextra -Werror -I. -I./include -c src/gtest-all.cc
ar rv libgtest.a gtest-all.o
g++ -std=c++11 -pthread -g -Wall -Wextra -Werror -I. -I./include -c src/gtest_main.cc
ar rv libgtest_main.a gtest_main.o

Make sure that sudo will run as root. This command may prompt you for your password. Then, it should display root. If you run it second time, it should not prompt you for your password. Then, you are ready to move on to the next step.

sudo whoami

Install the library for use:

sudo mkdir -p /usr/local/lib
sudo mv libgtest.a /usr/local/lib/libgtest.a
sudo chmod 644 /usr/local/lib/libgtest.a
sudo mv libgtest_main.a /usr/local/lib/libgtest_main.a
sudo chmod 644 /usr/local/lib/libgtest_main.a
sudo mkdir -p /usr/local/include
sudo mv include/gtest /usr/local/include
sudo chmod -R o+r /usr/local/include/gtest

For Linux/Windows:

sudo chown -R root:root /usr/local/include/gtest
sudo chown root:root /usr/local/lib/libgtest.a
sudo chown root:root /usr/local/lib/libgtest_main.a

For MacOS

sudo chown -R root:wheel /usr/local/include/gtest
sudo chown root:wheel /usr/local/lib/libgtest.a
sudo chown root:wheel /usr/local/lib/libgtest_main.a

Remove the source code, it’s no longer needed.

cd ../..
rm -r googletest-1.10.x
rm googletest-1.10.x.zip
or
rm googletest-1.10.x.tar.gz 

Last Updated 08/31/2020