2012-02-07 71 views
1

我正在构建一个与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 

我排除这两个库之后,我不能够使用字符串流或COUT,因为我得到以下编译错误:

error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > std::cout" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]) 
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)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) referenced in function [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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> > *)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@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)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 *)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) referenced in function "protected: virtual int __thiscall std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::overflow(int)" ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
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 " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IBEPADXZ) referenced in function "protected: virtual int __thiscall std::basic_stringbuf<char,struct std::char_traits<char>,class std::allocator<char> >::overflow(int)" ([email protected][email protected][email protected]@[email protected]@V?$alloca[email protected]@[email protected]@[email protected]@[email protected]) 

任何人都遇到类似的错误S'

+0

听起来像OpenCV静态库是为了链接到不同的MSVS运行时。您是否阅读发行说明? – 2012-02-08 00:01:26

+1

请参阅:http://stackoverflow.com/editing-help以获取格式帮助。 – 2012-02-08 00:05:34

回答

0

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

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