http://social.msdn.microsoft.com/Forums/vstudio/en-US/33d20497-d7c1-4b02-bc99-3bd933d57a3e/ni4882-link-error-with-static-runtime-lib-mtd-option?forum=vcgeneral
正在链接... LINK : warning LNK4098: 默认库“LIBCMT”与其他库的使用冲突;请使用
/NODEFAULTLIB:library libcpmtd.lib(cerr.obj) : error LNK2001: 无法解析的外部符号
__CrtDbgReportW libcpmtd.lib(stdthrow.obj) : error LNK2001: 无法解析的外部符号
__CrtDbgReportW libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号
__CrtDbgReportW libcpmtd.lib(cout.obj) : error LNK2001: 无法解析的外部符号
__CrtDbgReportW libcpmtd.lib(xdebug.obj) : error LNK2019: 无法解析的外部符号
__malloc_dbg,该符号在函数 "void * __cdecl operator new(unsigned int,struct
std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
中被引用 libcpmtd.lib(xmbtowc.obj) : error LNK2001: 无法解析的外部符号
__malloc_dbg libcpmtd.lib(xdebug.obj) : error LNK2019: 无法解析的外部符号 __free_dbg,
该符号在函数 "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,
char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z) 中被引用 libcpmtd.lib(xmbtowc.obj)
: error LNK2001: 无法解析的外部符号 __free_dbg libcpmtd.lib(_tolower.obj) :
error LNK2019: 无法解析的外部符号 __calloc_dbg,该符号在函数 __Getctype 中被引用
后来发现是单线程/多线程的问题,描述如下: 运行时库现在包含可防止混合不同类型的指令。
如果试图在同一个程序中使用不同类型的运行时库或使用调试和非调试版本的运行时库,则将收到
此警告。例如,如果编译一个文件以使用一种运行时库,而编译另一个文件以使用另一种运行时库
(例如单线程运行时库对多线程运行时库),并试图链接它们,则将得到此警告。应将所有源文件
编译为使用同一个运行时库。有关更多信息,请参见使用运行时库(/MD、/MT 和 /LD)编译器选项。
解决方案: 于是打开项目属性,在“配置属性-->C/C++-->代码生成-->运行时库”中将
“多线程(/MT)”修改为“多线程调试(/MTd)”, 或者Project -> ** Properties->
Configuration Properties -> C/C++ -> Code Generation -> Runtime Library ->
Multi-threaded (/MT) 改为 Multi-threaded Debug (/MTd) 再重新调试一下,问题解决。
error LNK2019: unresolved external symbol "public: __thiscall Leap::Frame::Frame(class Leap::FrameImplementation *)" (??0Frame@Leap@@QAE@PAVFrameImplementation@1@@Z) referenced in function "public: void __thiscall AngleListener::initVars(void)" (?initVars@AngleListener@@QAEXXZ)
代码如下:
class AngleListener : public Listener {
public:
void initVars();
private:
Frame oldframe;
}
void AngleListener::initVars(){
std::cout << "No Focused , init vars" << std::endl;
isFocus = false;
oldframe = NULL;
}
看下Frame定义
class Frame : public Interface {
public:
// For internal use only.
Frame(FrameImplementation*);
LEAP_EXPORT Frame();
}
所以这样语法是不对的,相当于用NULL来初始化一个类对象。这样肯定是不对的,应该是
oldframe = Frame();或者Frame f= frame();
oldframe = Frame(f);也可以这样子 前提是Frame要有相应的构造函数 不然也会出现刚才的问题。
本文解决了在使用Visual Studio编译时遇到的LINK4098和LNK2001等链接错误,并提供了调整运行时库设置的方法。同时,通过一个具体的代码示例说明了如何正确地初始化类对象。


被折叠的 条评论
为什么被折叠?



