error LNK2005: "void __cdecl operator delete(void *)"错误解决方案

xingyun86 2017-10-12 4898

方法一:

修改project->setting->General->Use of MFC为Use mfc in a shared dll

方法二:

修改project->setting->General->Use of MFC为Use Standard Windows Libraries

然后在project->setting->Linker->input->Additional Dependencies中加入XXXD.LIB, LIBCMTD.LIB(即为更改库的链接顺序)

方法三:

修改project->setting->General->Use of MFC为Use Standard Windows Libraries

修改project->setting->Precompiled Headers->Procompiled Header为Use(/Yu)

Precompiled Header File为默认stdafx.h

然后在stdafx.h中加入

#pragma comment(lib, "XXXD.LIB")

#pragma comment(lib, "LIBCMTD.LIB")

(此步骤亦可更改库的链接顺序)

若编译碰到无法找到

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup错误,莫慌,解决办法如下:

如果是ANSI版本:#pragma comment(linker,"/ENTRY:WinMainCRTStartup")

如果是UNICODE版本:#pragma comment(linker,"/ENTRY:wWinMainCRTStartup")


以上完毕,接下来贴出我自己更改后的StdAfx.h

MFC应用程序:

使用系统标准链接库、开启预编译头文件(/Yu)、多线程(/MT)/多线程调试(/MTD)配置

Multi-threaded Debug (/MTd)、Multi-threaded (/MT)

====================================================

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//
// Author: xingyun86
// Date: 2017-10-1

#if !defined(AFX_STDAFX_H__E204F3C2_DFB4_41B6_A679_35B42388C8D2__INCLUDED_)
#define AFX_STDAFX_H__E204F3C2_DFB4_41B6_A679_35B42388C8D2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
#if !defined(_DEBUG) && !defined(DEBUG)
//如果是RELEASE选项
#if !defined(_UNICODE) && !defined(UNICODE)
//如果是RELEASE选项下的ANSI选项
#pragma comment(linker,"/ENTRY:WinMainCRTStartup")
#pragma comment(lib, "nafxcw.lib")
#else
//如果是RELEASE选项下的UNICODE选项
#pragma comment(linker,"/ENTRY:WinMainCRTStartup")
#pragma comment(lib, "uafxcw.lib")
#endif
#pragma comment(lib, "libcmt.lib")
#else
//如果是DEBUG选项
#if !defined(_UNICODE) && !defined(UNICODE)
//如果是DEBUG选项下的ANSI选项
#pragma comment(linker,"/ENTRY:WinMainCRTStartup")
#pragma comment(lib, "nafxcwd.lib")
#else
//如果是DEBUG选项下的UNICODE选项
//#pragma comment(linker, "/nodefaultlib:libcmtd.lib")
#pragma comment(linker,"/ENTRY:wWinMainCRTStartup")
#pragma comment(lib, "uafxcwd.lib")
#endif
#pragma comment(lib, "libcmtd.lib")
#endif
//#pragma comment(linker, "/nodefaultlib")
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>			// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__E204F3C2_DFB4_41B6_A679_35B42388C8D2__INCLUDED_)


×
打赏作者
最新回复 (0)
查看全部
全部楼主
返回