Google 测试预构建 VS 2013

Google Test pre-build VS 2013

我有一个使用编译器 VS2008 编译的解决方案。它工作完美。它使用 Google 测试进行检测,并且 Google 测试库链接到解决方案。据我所知,gtest.lib 应该使用与解决方案本身相同的编译器进行编译。

现在,我必须使用 VS2013 编译相同的解决方案。我得到这个编译错误

Error   3   error LNK2038: mismatch detected for '_MSC_VER': 
value '1700' doesn't match value '1800'  

我认为我应该获取使用 Visual Studio 2013 编译的 Google 测试库。

我找不到这样的东西。 你能给我一个关于我应该去的 Google 测试库的提示吗?

你得到的 linker 错误非常明显:你需要一个用 VS2013 编译的 gtest.lib

"I think that I should get the library for Google Test compiled with Visual Studio 2013."

没错,所以就这样

"Could you give me a hint at the Google Test library I should go for ?"

好吧,不再引用 google test primer documentation(强调我的),抱歉(我怀疑您是否可以在其他地方可靠地下载适当的二进制文件):

Setting up a New Test Project

To write a test program using Google Test, you need to compile Google Test into a library and link your test with it. We provide build files for some popular build systems: msvc/ for Visual Studio, xcode/ for Mac Xcode, make/ for GNU make, codegear/ for Borland C++ Builder, and the autotools script (deprecated) and CMakeLists.txt for CMake (recommended) in the Google Test root directory. If your build system is not on this list, you can take a look at make/Makefile to learn how Google Test should be compiled (basically you want to compile src/gtest-all.cc with GTEST_ROOT and GTEST_ROOT/include in the header search path, where GTEST_ROOT is the Google Test root directory).

Once you are able to compile the Google Test library, you should create a project or build target for your test program. Make sure you have GTEST_ROOT/include in the header search path so that the compiler can find "gtest/gtest.h" when compiling your test. Set up your test project to link with the Google Test library (for example, in Visual Studio, this is done by adding a dependency on gtest.vcproj).

If you still have questions, take a look at how Google Test's own tests are built and use them as examples.

我个人更喜欢使用 src/gtest-all.cc 来构建测试运行程序,并 link 从源代码中使用我的测试项目。这是最简单和最便携的方式恕我直言(使用例如您的自定义 GNU makefile)。

正如您在 OP 的评论中所说,您可以轻松地使用您的 VS2013 编译器 "prebuild",从其他编译器 link项目。

请注意,native GTEST package on NuGet 包含 gtest.lib。具有使 gtest include 文件夹自动可用的额外好处。