c++ - 谷歌测试预构建 VS 2013

标签 c++ visual-studio linker-errors googletest

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

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

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

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

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

最佳答案

您得到的链接器错误非常明显:您需要使用 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 来构建测试运行器,并将其与我的源代码测试项目链接起来。这是最简单和最便携的方式恕我直言(使用例如您的自定义 GNU makefile)。

正如在对您的 OP 的评论中所说,您可以轻松地“预构建” 只需使用您的 VS2013 编译器,以便从其他项目链接它。

关于c++ - 谷歌测试预构建 VS 2013,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28694252/

相关文章:

c++11 用户定义文字,与编译/执行二分法冲突

c++ - 为什么我的 cout 语句没有打印一半?

sql - 在仅包含数据库 dbproj 项目的 VS 解决方案中使用 nuget 来引用其他 dbproj 文件

linux - 对符号 'pthread_key_delete@@GLIBC_2.2.5 的 undefined reference

c - 在 ubuntu 12.04 上制作 openwsman 时出错

c++ - std::move 和 unique_ptr::reset 之间有什么区别?

C++:最大整数

c++ - 为什么我的鼠标光标坐标突然缩放?

c# - 加载 Matlab 程序集时流氓等待 40 秒......如何诊断原因?

c# - VC++ 在解决方案中从非/clr 项目的函数调用/clr 项目的函数