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 有什么区别?


- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01