What#39;s the difference between gtest.lib and gtest_main.lib?(gtest.lib 和 gtest_main.lib 有什么区别?)
问题描述
Google 的 C++ 测试框架有两个输出库:一个是 gtest.lib,另一个是 gtest_main.lib.根据 Nik Reiman 的回答 如何使用 Visual Studio 设置 gtest,我们应该链接到 gtest_main.lib,但我正在链接到 gtest.lib,并且我的示例测试用例运行良好.
Google's C++ Test Framework has two output libraries: one is gtest.lib and the other one is gtest_main.lib. According to Nik Reiman's answer on how to setup gtest with Visual Studio, we should link to gtest_main.lib but I'm linking to gtest.lib and the sample test cases that I have are running fine.
这两个库有什么区别,我链接到哪个库有关系吗?
What's the difference between the two libraries and does it matter which one I link to?
推荐答案
唯一合理的区别是 gtest_main.lib 提供了一个测试应用程序入口点的默认实现(即 main
函数):
the only reasonable difference is that gtest_main.lib provides a default implementation of a test application entry point (i.e. main
function):
引自 入门使用 Google C++ 测试框架:
"[...] 也许你认为写作所有这些 main() 函数太多了工作?我们完全同意您的看法,并且这就是为什么 Google Test 提供了一个main() 的基本实现.如果它适合您的需求,然后只需链接您的用 gtest_main 库和你测试很好."
"[...] maybe you think that writing all those main() functions is too much work? We agree with you completely and that's why Google Test provides a basic implementation of main(). If it fits your needs, then just link your test with gtest_main library and you are good to go."
如果您想自己编写 main 函数 - 您应该链接到 gtest.lib.
If you want to write your main function yourself - you should link with gtest.lib.
这篇关于gtest.lib 和 gtest_main.lib 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:gtest.lib 和 gtest_main.lib 有什么区别?


基础教程推荐
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01