Visual Studio LNK2005 error

环境:  Visual Studio 2008 C++

编译错误: error LNK2005: _DllMain@12 already defined …

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.

微软的支持文档指出,MFC库的链接必须在CRT库之前,而解决方法有2种:

1. 强制连接器以正确的顺序链接,具体方法见下面的微软链接。

2. 在Linker标签页中,找到Command Line属性,并添加附加选项: /verbose:lib,重新编译工程,工程会列出详细的库清单,根据输出的内容来修正有问题的组件。

其中如果使用的是MFC库,确保每一个工程文件都包含头文件 #include <Stdafx.h>。

http://support.microsoft.com/kb/148652

Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

Canonical URL by SEO No Duplicate WordPress Plugin