gpt4 book ai didi

visual-studio-2010 - 由于其他依赖库,在 VS2010 中链接 googleTest 结果为 LNK2005

转载 作者:太空宇宙 更新时间:2023-11-04 14:08:17 24 4
gpt4 key购买 nike

我有一个庞大而复杂的项目,最终要进行单元测试。我已经使用 Visual Studio 2010 在本地构建了 googleTest 1.6.0,项目文件是按照 README 指定的那样使用 cmake 构建的。

这个项目有很多静态和动态链接的依赖库。其中许多是专有的。所有链接尝试都会产生 220 个此类错误。这是一个示例:

msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __cdecl std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QEAAXXZ) already defined in gtest.lib(gtest-all.obj)

libcpmtd.lib(cerr.obj) : error LNK2005: "protected: char * __cdecl std::basic_streambuf >::_Gndec(void)" (?_Gndec@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAPEADXZ) already defined in msvcprtd.lib(MSVCP100D.dll)

LIBCMTD.lib(setlocal.obj) : error LNK2005: _configthreadlocale already defined in MSVCRTD.lib(MSVCR100D.dll)

LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library

fatal error LNK1169: one or more multiply defined symbols found

我已经尝试了/NODEFAULTLIB 标志,并且我试图按照建议仅忽略 msvcprtd.lib、MSVCRTD.lib 和 LIBCMTD.lib,但后来我遇到了无法解析的符号问题...

项目和 googleTest 都是用 x64、/MP、/MDd 编译的,没有/clr。

我一直在研究编译器标志,想知道是否存在某种版本不匹配。 Dumpbin,就我的理解而言,并没有暗示任何我可能理解的东西。我希望有一个呃

最佳答案

您的问题似乎已在 Google Talk 的 FAQ 中得到解答.确保您所有的库都使用/MD(d) 设置。

You may get a number of the following linker error or warnings if you attempt to link your test project with the Google Test library when your project and the are not built using the same compiler settings.

  • LNK2005: symbol already defined in object
  • LNK4217: locally defined symbol 'symbol' imported in function 'function'
  • LNK4049: locally defined symbol 'symbol' imported The Google Test project (gtest.vcproj) has the Runtime Library option set to /MT (use multi-threaded static libraries, /MTd for debug). If your project uses something else, for example /MD (use multi-threaded DLLs, /MDd for debug), you need to change the setting in the Google Test project to match your project's.

To update this setting open the project properties in the Visual Studio IDE then select the branch Configuration Properties | C/C++ | Code Generation and change the option "Runtime Library". You may also try using gtest-md.vcproj instead of gtest.vcproj.

关于visual-studio-2010 - 由于其他依赖库,在 VS2010 中链接 googleTest 结果为 LNK2005,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15993912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com