您的位置:首页 > 大数据 > 人工智能

error LNK2005: _DllMain@12 already defined in MSVCRTD.lib

2016-04-26 18:12 597 查看
本文主要分析和解决编译链接时产生的 LNK2005 错误。
【错误信息】: mfcs90ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj)【分析原因】: 这篇文章:《在Visual C++中以错误的顺序链接CRT库和MFC库时出现LNK2005错误》详细分析和说明了产生这种错误的原因。 简单地说,就是产生错误的工程同时使用了CRT库和MFC库,并且链接顺序不对,CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。【解决方法】:[align=left]
在“项目 -> 属性 -> 链接器 -> 命令行”栏中,输入 /verbose:lib编译参数,这样,就可以在output窗口看到链接时搜索的库的先后顺序,对于本问题,你一定可以看到类似下面的先后输出:[/align][align=left] [/align]
ortant; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; line-height: 1.3em; list-style-image: initial; list-style-type: decimal-leading-zero; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial;"   >>    Searching D:\vs2008\VC\lib\MSVCRTD.lib:
ortant; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: rgb(92, 92, 92); line-height: 1.3em; list-style-image: initial; list-style-type: decimal-leading-zero; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-width: initial; border-color: initial;"   >>    Searching D:\vs2008\VC\atlmfc\lib\mfcs90ud.lib:
[align=left] 由此可以看出,默认情况下,先链接了CRT库MSVCRTD.lib,然后链接的是MFC的库mfcs90ud.lib,因此,需要强制改变一下它们的链接顺序。

选择:菜单“项目”-->“设置”->链接-->Input。
在第一行“对象/库模块”中最前面输入mfcs90ud.lib;MSVCRTD.lib
在第二行“忽略库”框中,输入mfcs90ud.lib;MSVCRTD.lib。
确定,重新链接,通过![/align][align=left] [/align][align=left]【知识扩展】:

顺便普及一下编译参数/VERBOSE的其他用法。 该说明的官方网址点击:这里
[/align][align=left][/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: