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

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

问题描述

Debian不再为gTest提供任何预编译的软件包。他们建议您将框架集成到您的项目makefile中。但我想保持我的make文件清洁。如何设置gTest类似以前的版本(<1.6.0),以便我可以链接到aganist库?

Debian does not provide any precompiled packages for gTest anymore. They suggest you to integrate the framework into your projects makefile. But I want to keep my make file clean. How do I setup gTest like the former versions (<1.6.0), so that I can link aganist 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.7.0.tar.gz

或者取得。我想我不会维护这个小小的操作方法,所以如果你偶然发现它,并且链接已过时,请自由编辑它。

Or get it by hand. I guess 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.7.0.tar.gz
cd googletest-release-1.7.0
cmake -DBUILD_SHARED_LIBS=ON .
make



3



此步骤可能与distro不同,因此请确保将标题和库复制到正确的目录中。我通过检查 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 include/gtest /usr/include
$ sudo cp -a libgtest_main.so libgtest.so /usr/lib/



4。更新链接器的缓存



...并检查GNU链接器是否知道libs

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 about the framework to learn how it works. Happy coding!

编辑:
这也适用于OS X!请参见如何在OS X上正确设置googleTest

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

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