I am trying to install Google Test according to this answer on Ubuntu without root access, as I need learn and use it at work.
Managed to get these done in my own user folder:
$ mkdir ~/temp
$ cd ~/temp
$ unzip gtest-1.7.0.zip
$ cd gtest-1.7.0
$ mkdir mybuild
$ cd mybuild
$ cmake -DBUILD_SHARED_LIBS=ON -Dgtest_build_samples=ON -G"Unix Makefiles" ..
$ make
It seems I already have gtest in /usr/src/gtest altough I don't want to use this, because it was not me who installed it and I'm not sure about its version, nor in its availability. Can't even delete it without permission.
Still the instruction ends as:
$ cp -r ../include/gtest ~/usr/gtest/include/
$ cp lib*.so ~/usr/gtest/lib
What am I missing here?
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 directoryCWD
(whereCWD
is not/home/me/
).Then in
CWD
:-After this, you will find:-
You can then use gtest/gmock headers in your source code like:
and compile and link a gtest/gmock program like:
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
orCWD/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.