如何使用Visual Studio 2005设置Google C ++测试框架(gtest) [英] How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005

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

问题描述

该文件未在网站上记录,人们似乎在设置框架时遇到问题.有人可以显示示例项目设置的分步介绍吗?

It is not documented on the web site and people seem to be having problems setting up the framework. Can someone please show a step-by-step introduction for a sample project setup?

推荐答案

Arlaharen所说的基本上是正确的,除了他省略了解释链接器错误的那一部分.首先,您需要在没有CRT的情况下构建应用程序 作为运行时库.无论如何,您始终应该这样做,因为它确实简化了应用程序的分发.如果您不这样做,那么所有用户都需要安装Visual C ++运行时库,而那些没有这样做的用户将抱怨系统上缺少神秘的DLL……链接所花费的额外数百KB静态地使用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 ++->代码生成->运行时库,对于您的Release版本和多线程",需要将其设置为多线程".调试".

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库是以相同的方式构建的,因此您需要确保链接的是正确版本的 it ,否则链接器将提取运行时库的另一个副本,这是您看到的错误(顺便说一句,无论是否使用MFC,这都不会有所作为).您需要以 Debug and Release 模式构建gtest,并保留两个副本.然后,在Release版本中链接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天全站免登陆