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

查看:37
本文介绍了如何在 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?

推荐答案

在开始之前,请确保您已阅读并理解Google 的这篇笔记!本教程使 gtest 的使用变得简单,但可能会介绍 讨厌的错误.

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.安装"系统上的标头和库.

此步骤可能因发行版而异,因此请确保将标头和库复制到正确的目录中.我通过检查 Debian 以前的 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 googletest/include/gtest /usr/include
sudo cp -a googlemock/gtest/libgtest_main.so googlemock/gtest/libgtest.so /usr/lib/

4.更新链接器的缓存

...并检查 GNU Linker 是否知道这些库

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.

从这里开始,您可能想要访问 Googles 文档旧文档 了解框架的工作原理.快乐编码!

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!请参阅如何在操作系统上正确设置googleTestX"

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

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