【发布时间】:2013-10-14 09:07:24
【问题描述】:
当我使用 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 不是问题。从链接中删除此文件后,上述错误仍然存在。
【问题讨论】:
-
您是否在多个地方定义了相同的功能?我可以在脑海中对链接错误中的名称进行半解,但我需要查看代码以正确帮助而无需猜测
-
或者,您正在尝试构建别人的代码?
-
你有适合 VC9 的 boost_python-vc71-mt-1_32.lib 版本吗?
-
@doctorlove,什么功能?你的意思是
std::operator<<?它不是由我正在尝试构建的库定义的。 ;) -- 是的,我试图编译的不是我的代码。 -
我有点担心
/Zc:wchar_t-。 C++ 标准要求wchar_t是单独的类型,我希望 boost 依赖于此。使用和不使用/Zc:wchar_t-编译的代码肯定是不兼容的,可能会导致奇怪的链接器错误。
标签: c++ templates visual-c++ linker