"how to install google test on ubuntu without root access?" Code Answer

1

let's say you want to install googletest in /home/me/googletest.

browse to the googletest github repo https://github.com/google/googletest. (do not use a possibly -out-of-date version you may have got elsewhere.)

using the clone or download link, either clone or download-and-extract the source as (let's say) ./googletest under your current directory cwd (where cwd is not /home/me/).

then in cwd:-

$ mkdir googletest_build
$ cd googletest_build
$ cmake -dcmake_install_prefix:path=/home/me/googletest ../googletest
$ make
$ make install

after this, you will find:-

/home/me/googletest/
                lib/
                    libgmock.a
                    libgmock_main.a
                    libgtest.a
                    libgtest_main.a
                include/
                        gmock/
                            # gmock header files
                        gtest/
                            # gtest header files

you can then use gtest/gmock headers in your source code like:

#include <gtest/gtest.h>
#include <gmock/gmock.h>

and compile and link a gtest/gmock program like:

g++ -pthread -i/home/me/googletest/include -c -o my-unit-tester.o my-unit-tester.cpp
g++ -o my-unit-tester my-unit-tester.o -l/home/me/googletest/lib -lgtest -lgmock -pthread

using the -i... option to tell the compiler where gtest/gmock headers reside and using the -l... option to tell the linker where gtest/gmock libraries reside.

pass -pthread to both compiler and linker because the gtest/gmock libraries are built multi-threading by default.

after installing you no longer need either cwd/googletest or cwd/googletest_build.

you may wish to pass additional options to cmake, in which case the build products will differ as per the meaning of those additional options.

By Hello Fishy on April 7 2022

Answers related to “how to install google test on ubuntu without root access?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.