如何在Visual Studio 2005上设置Google C ++测试框架(gtest) [英] How to setup Google C++ Testing Framework (gtest) on Visual Studio 2005

查看:257
本文介绍了如何在Visual Studio 2005上设置Google C ++测试框架(gtest)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它没有记录在网站上,人们似乎有问题设置框架。

It is not documented on the web site and people seems having problem setting up the framework. Can someone please show step by step introduction to a sample project setup.

推荐答案

Arlaharen说的基本上是对的,除了他没有该部分解释了链接器错误。首先,您需要将您的应用程序构建为,而不必将CRT作为运行时库。你应该总是这样做,因为它真的简化了你的应用程序的分发。如果你不这样做,那么所有的用户都需要安装Visual C ++运行时库,那些不会抱怨神秘的DLL在他们的系统上丢失的...对于链接所花费的几百千字节静态的CRT,你保存自己很多头痛后来支持(相信我在这一个 - 我学到了很难的方式!)。

What Arlaharen said was basically right, except he left out the part which explains your linker errors. First of all, you need to build your application without the CRT as a runtime library. You should always do this anyways, as it really simplifies distribution of your application. If you don't do this, then all of your users need the Visual C++ Runtime Library installed, and those who do not will complain about mysterious DLL's missing on their system... for the extra few hundred kilobytes that it costs to link in the CRT statically, you save yourself a lot of headache later in support (trust me on this one -- I've learned it the hard way!).

要做到这一点,你去目标的属性 - > C / C ++ - >代码生成 - >运行库,它需要设置为多线程为您的发布版本和多线程调试为您的调试

Anyways, to do this, you go to the target's properties -> C/C++ -> Code Generation -> Runtime Library, and it needs to be set as "Multi-Threaded" for your Release build and "Multi-Threaded Debug" for your Debug build.

由于gtest库是以相同的方式构建的,因此您需要确保您正在链接到正确的版本 或者链接器会拉入运行时库的另一个副本,这是你看到的错误(btw,如果你使用MFC,这不应该有什么区别)。您需要将gtest构建为调试和发布模式并保留这两个副本。然后,在您的发行版本中将gtest.lib / gtest_main.lib和您的Debug版本中的gtestd.lib / gtest_maind.lib链接。

Since the gtest library is built in the same way, you need to make sure you are linking against the correct version of it, or else the linker will pull in another copy of the runtime library, which is the error you saw (btw, this shouldn't make a difference if you are using MFC or not). You need to build gtest as both a Debug and Release mode and keep both copies. You then link against gtest.lib/gtest_main.lib in your Release build and gtestd.lib/gtest_maind.lib in your Debug build.

此外,你的应用程序指向gtest头文件存储的目录(在属性 - > C / C ++ - >常规 - >附加包含目录),但如果你得到链接器错误,我认为你已经管理得到这个部分正确,否则你会有更多的编译器错误先处理。

Also, you need to make sure that your application points to the directory where the gtest header files are stored (in properties -> C/C++ -> General -> Additional Include Directories), but if you got to the linker error, I assume that you already managed to get this part correct, or else you'd have a lot more compiler errors to deal with first.

这篇关于如何在Visual Studio 2005上设置Google C ++测试框架(gtest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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