使用stringstream链接错误

时间:2012-02-07 23:59:36

标签: c++ opencv

我正在构建一个与OpenCV库静态链接的win32应用程序。在第一次尝试时,我被构建日志指示忽略默认库,msvcprtd.lib和libcmtd.lib,因为有很多链接错误,例如

"LIBCMTD.lib(sprintf.obj) : error LNK2005: _sprintf already defined in MSVCRTD.lib(MSVCR100D.dll)"

构建日志中的最后两句话是

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

在我排除这两个库后,我无法使用stringstream或cout,因为我收到以下构建错误:

error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > std::cout" (__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A)
1>run.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall std::basic_iostream<char,struct std::char_traits<char> >::~basic_iostream<char,struct std::char_traits<char> >(void)" (__imp_??1?$basic_iostream@DU?$char_traits@D@std@@@std@@UAE@XZ) referenced in function __unwindfunclet$??0?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z$0
1>run.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_iostream<char,struct std::char_traits<char> >::basic_iostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *)" (__imp_??0?$basic_iostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@@Z) referenced in function "public: __thiscall std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> >::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> >(int)" (??0?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z)
1>run.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *,char *)" (__imp_?setp@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IAEXPAD00@Z) referenced in function "protected: virtual int __thiscall std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::overflow(int)" (?overflow@?$basic_stringbuf@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@MAEHH@Z)
1>run.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: char * __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::pbase(void)const " (__imp_?pbase@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IBEPADXZ) referenced in function "protected: virtual int __thiscall std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::overflow(int)" (?overflow@?$basic_stringbuf@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@MAEHH@Z)

有人遇到过类似的错误吗?

1 个答案:

答案 0 :(得分:0)

每当Visual Studio开始抱怨MSVCRTD.libLIBCMTD.lib之间的冲突时,您可以确定您将在Microsft运行时元素中不一致链接的项目链接在一起。

您提到您正在使用的OpenCV是静态链接的,我敢打赌您的项目是动态链接的。您应该设置解决方案文件,以便静态链接所有项目或动态链接所有项目。