gpt4 book ai didi

c++ - 链接期间模板实例发生冲突

转载 作者:行者123 更新时间:2023-11-30 04:13:38 24 4
gpt4 key购买 nike

当我使用 VC9 + Win SDK 7.0A 构建库(不常见,所以我不会命名)时,出现如下错误。所有这些错误都与模板函数有关。什么会导致它以及如何处理它? -- 在底部附加编译器命令和链接器命令。

我真的被这件事困扰了。模板不是可以在许多库/目标文件中使用相同的参数多次实例化吗?

msvcprt.lib(MSVCP90.dll) : error LNK2005: 
"class std::basic_ostream<char,struct std::char_traits<char> > &
__cdecl std::operator<<<struct std::char_traits<char> > (
class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)"
(??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
already defined in CvBuildLists.obj

编译器

"(...)\Microsoft Visual Studio 9.0\VC\bin\cl.exe" /nologo /MD /Zi /O2 /Oy /Oi- 
/DNDEBUG /Fp"Release\CvGameCoreDLL.pch" /GR /Gy /W3 /EHsc /arch:SSE2 /Gd /Gm-
/DWIN32 /D_WINDOWS /D_USRDLL /DCVGAMECOREDLL_EXPORTS /Yu"CvGameCoreDLL.h" /Zm200
/Zc:wchar_t- /D_CRT_NON_CONFORMING_SWPRINTFS /D_CRT_SECURE_NO_WARNINGS
(some library specific definitions)
/I"(...)\Microsoft Visual Studio 9.0\VC/include"
/I"(...)\Microsoft SDKs\Windows\v7.0A/Include"
/I"(...)\Microsoft SDKs\Windows\v7.0A/Include/mfc"
/I"(...)\Boost-1.32.0/include" /I"(...)\Python24/include"
/I"(...)\xerces-c-3.1.1/src"
/YcCvGameCoreDLL.h /Fo"Release\CvBuildLists.obj"
/c CvBuildLists.cpp

链接器

"(...)\Microsoft Visual Studio 9.0\VC\bin\link.exe" 
/out:Release\CvGameCoreDLL.dll /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF
/IMPLIB:"Release\CvGameCoreDLL.lib" /PDB:"Release\CvGameCoreDLL.pdb" /DLL
/NOLOGO /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /TLBID:1 /DEF:CvGameCoreDLL.def
/NODEFAULTLIB:LIBCMT (-- not sure about this, but without it, the mentioned errors looks the same)
/LIBPATH:"(...)\Python24/libs" /LIBPATH:"(...)\Boost-1.32.0/libs/"
boost_python-vc71-mt-1_32.lib thread.obj exceptions.obj condition.obj xtime.obj
mutex.obj once.obj recursive_mutex.obj read_write_mutex.obj tss_hooks.obj
/LIBPATH:"(...)\Microsoft Visual Studio 9.0\VC/lib"
/LIBPATH:"(...)\Microsoft SDKs\Windows\v7.0A/Lib" /
/LIBPATH:"(...)\xerces-c-3.1.1\Build\C2C\Release"
winmm.lib user32.lib psapi.lib
(many .obj-s and .res)
(the xerces's lib is actually excluded from building)

编辑

忘记了。 -- 当使用 VC7.1 代替 VC9 时,库可以正确构建。

编辑2boost_python-vc71-mt-1_32.lib 不是问题。从链接中删除此文件后,上述错误仍然存​​在。

最佳答案

您的编辑表明问题与模板无关,而是包含运行时库不一致。例如,您告诉链接器使用 boost_python-vc71-mt-1_32.lib 并说它适用于 VC7.1 但不适用于 VC9。
首先,确保你有适合新版本的 visual studio 的 boost 库。
其次,虽然这是一个相关点,但请确保您使用的所有库都依赖于相同的运行时。

关于c++ - 链接期间模板实例发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19356849/

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