How to solve problem caused when the CRT library and MFC libraries are linked in the wrong order

SYMPTOMS

<script type="text/javascript">loadTOCNode(1, 'symptoms');</script> When the C Run-Time (CRT) library and Microsoft Foundation Class (MFC) libraries are linked in the wrong order, you may receive one of the following LNK2005 errors:
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int)"(??2@YAPAXI@Z) already
defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void __cdecl operator delete(void *)"(??3@YAXPAX@Z) already defined
in LIBCMTD.lib(dbgnew.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int,int,char const *,int)"
(??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj)
mfcs40d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in
MSVCRTD.LIB (dllmain.obj)
mfcs42d.lib(dllmodul.obj): error LNK2005: _DllMain@12 already defined in
msvcrtd.lib(dllmain.obj)
 

CAUSE

<script type="text/javascript">loadTOCNode(1, 'cause');</script> The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked.

RESOLUTION

<script type="text/javascript">loadTOCNode(1, 'resolution');</script> There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and to correct it.

Solution One: Force Linker to Link Libraries in Correct Order

1.    On the Project  menu, click Settings.
2.    In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
3.    On the Link tab, click to select Input in the Category combo box.
4.    In the "Ignore Specific Library" box, insert the library names (for example, Nafxcwd.lib;Libcmtd.lib). Note The linker command-line equivalent in /NOD:<library name>.
5.    In the "Additional Dependencies" box, insert the library names. You must make sure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib).

Solution Two: Locate and Correct the Problem Module

To view the current library link order, follow these steps:
1.    On the Project menu, click Settings.
2.    In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
3.    On the Linker->Command Line tab, type /verbose:lib in the Project Options box.
4.    Rebuild your project. The libraries will be listed in the output window during the linking process.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值