当我使用 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 时,库构建正确。
edit2
boost_python-vc71-mt-1_32.lib
不是问题。从链接中删除此文件后,上述错误仍然存在。