如何在Linux上将googleTest设置为共享库 [英] How to set up googleTest as a shared library on Linux

查看:94
本文介绍了如何在Linux上将googleTest设置为共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Debian不再为gTest提供任何预编译的软件包.他们建议您将框架集成到项目的makefile中.但是我想保持我的makefile干净.如何像以前的版本(< 1.6.0)一样设置gTest,以便可以链接到库?

Debian does not provide any precompiled packages for gTest anymore. They suggest you integrate the framework into your project's makefile. But I want to keep my makefile clean. How do I set up gTest like the former versions (<1.6.0), so that I can link against the library?

推荐答案

在开始之前,请确保您已阅读并理解 讨厌的错误.

Before you start make sure your have read and understood this note from Google! This tutorial makes using gtest easy, but may introduce nasty bugs.

wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz

或者通过获取.我不会保留这小小的操作方法",因此,如果您偶然发现了它,并且链接已过时,请随时对其进行编辑.

Or get it by hand. I won't maintain this little How-to, so if you stumbled upon it and the links are outdated, feel free to edit it.

tar xf release-1.8.0.tar.gz
cd googletest-release-1.8.0
cmake -DBUILD_SHARED_LIBS=ON .
make

3.在系统上安装"标头和库.

此步骤在发行版之间可能有所不同,因此请确保将标头和库复制到正确的目录中.我通过检查 Debians前gtest库的位置来完成此操作.但我敢肯定,有更好的方法可以做到这一点.注意:make install是危险的,不受支持

3. "Install" the headers and libs on your system.

This step might differ from distro to distro, so make sure you copy the headers and libs in the correct directory. I accomplished this by checking where Debians former gtest libs were located. But I'm sure there are better ways to do this. Note: make install is dangerous and not supported

sudo cp -a include/gtest /usr/include
sudo cp -a libgtest_main.so libgtest.so /usr/lib/

4.更新链接器的缓存

...并检查GNU链接程序是否知道这些库

4. Update the cache of the linker

... and check if the GNU Linker knows the libs

sudo ldconfig -v | grep gtest

如果输出如下所示:

libgtest.so.0 -> libgtest.so.0.0.0
libgtest_main.so.0 -> libgtest_main.so.0.0.0

,一切都很好.

gTestframework现在可以使用了.只是不要忘记通过将-lgtest设置为链接器标志来将您的项目链接到库,如果没有编写自己的测试主例程,则可以设置显式的-lgtest_main标志.

gTestframework is now ready to use. Just don't forget to link your project against the library by setting -lgtest as linker flag and optionally, if you did not write your own test mainroutine, the explicit -lgtest_main flag.

从这里开始,您可能想要转到Google的文档

From here on you might want to go to Googles documentation, and the old docs about the framework to learn how it works. Happy coding!

这也适用于OS X!请参阅如何在OS X上正确设置googleTest "

This works for OS X too! See "How to properly setup googleTest on OS X"

这篇关于如何在Linux上将googleTest设置为共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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