如何在没有root用户访问权限的Ubuntu上安装Google Test? [英] How to install Google Test on Ubuntu without root access?

查看:121
本文介绍了如何在没有root用户访问权限的Ubuntu上安装Google Test?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据此答案在没有root访问权限的Ubuntu上安装Google Test,因为我需要学习和使用它在工作.

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

似乎我已经不想在/usr/src/gtest中使用gtest了,因为不是我安装了它,也不知道它的版本或可用性.未经允许,甚至无法删除它.

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

我在这里想念什么?

推荐答案

假设您要在/home/me/googletest中安装googletest.

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

浏览到googletest GitHub存储库https://github.com/google/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.)

使用克隆或下载链接进行克隆或下载并提取 来源为(例如)您当前目录CWD(其中CWD不是/home/me/)下的./googletest.

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/).

然后在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

然后您可以在源代码中使用gtest/gmock标头,例如:

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

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

并编译并链接gtest/gmock程序,例如:

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

使用-I...选项告诉编译器gtest/gmock标头位于何处,以及 使用-L...选项告诉链接程序gtest/gmock库在哪里.

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.

-pthread传递给编译器和链接器,因为gtest/gmock库是 默认情况下建立多线程.

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

安装后,您不再需要CWD/googletestCWD/googletest_build.

After installing you no longer need either CWD/googletest or CWD/googletest_build.

您可能希望将其他选项传递给cmake,在这种情况下,构建产品将根据这些其他选项的含义而有所不同.

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.

这篇关于如何在没有root用户访问权限的Ubuntu上安装Google Test?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆