gtest.lib 和 gtest_main.lib 有什么区别? [英] What's the difference between gtest.lib and gtest_main.lib?

查看:24
本文介绍了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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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