c – 添加类后的项目链接错误
作者:互联网
我正在编写一个3D图像引擎(它读取带有场景信息的XML并用openGL打印),用于大学,在visual studio中(不幸的是……),我正在做解析器atm,它将xml读入一个简单的树状数据结构.其中一个元素是Camera,在我添加数据结构的那部分之前,程序运行正常,但是在我添加它之后,我遇到以下错误:
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ) already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(_fpinit_.obj) : error LNK2005: __fltused already defined in a previous module
1>LIBCMT.lib(_fpinit_.obj) : error LNK2005: __ldused already defined in a previous module
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isalpha already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isspace already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(_ctype.obj) : error LNK2005: _isalnum already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
1>LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in MSVCRTD.lib(MSVCR100D.dll)
1>LIBCMT.lib(strtol.obj) : error LNK2005: _strtol 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 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>bin\CGFexample.exe : fatal error LNK1169: one or more multiply defined symbols found
我无法理解为什么添加一个简单的新类会产生如此奇怪的错误,任何人都可以帮忙吗?
附:如果需要,我会添加相机类,但它实际上只是一堆带有集合的变量和获取和两个子类(有两种类型的相机),我不认为问题是因为类本身无论如何.
解决方法:
正如@John所提到的,您应该使用动态或静态C运行时链接.在Visual Studio中,这由RunTime Library属性(C/C++文件夹>代码生成>运行时库属性)控制. C运行时有4个选项:debug / release&静态/动态.
附注:如果您使用的是第三方dll,清单文件应该会为您提供有关正在使用的运行时的一些信息.你可以使用像Dependency Walker这样的工具仔细检查它(如果是动态的话,你会看到一个名为MSVCRXXX.DLL的dll),其中XXX版本为VC,D版本为调试版
标签:c,linker-errors 来源: https://codeday.me/bug/20190728/1565496.html