How to install Google Test on Ubuntu without root access?

I am trying to install Google Test according to this answer on Ubuntu without root access, since I need to learn and use it at work.

I managed to do this 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 that I already have gtest in / usr / src / gtest, although I do not want to use it because it is not me who installed it, and I am not sure about its version and its availability. You cannot even delete it without permission.

As before, the command ends as:

$ cp -r ../include/gtest ~/usr/gtest/include/
$ cp lib*.so ~/usr/gtest/lib

What am I missing here?

+3
source share
1 answer

Suppose you want to install googletest in /home/me/googletest.

googletest GitHub https://github.com/google/googletest. ( , , , , , .)

, , - () ./googletest CWD ( CWD /home/me/).

CWD: -

$ mkdir googletest_build
$ cd googletest_build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/me/googletest ../googletest
$ make
$ make install

: -

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

gtest/gmock , :

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

gtest/gmock, :

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

-I..., , gtest/gmock, -L..., , gtest/gmock.

-pthread , , gtest/gmock .

CWD/googletest CWD/googletest_build.

, cmake, .

+4

Source: https://habr.com/ru/post/1649184/


All Articles