我有一个使用编译器 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/