错误请#define _AFXDLL或在项目属性中进行更改后不要使用/ MD [d]

Say*_*liK 41 dll mfc visual-c++

我正在使用Visual Studio 2011中的Win32项目.当我包含afx.h或afxwin.h时,它正在生成MFC错误.为了解决这个问题,我在Project Properties选项卡中进行了以下更改:1)使用MFC:在共享DLL中使用MFC 2)C++ - >代码生成 - >运行时库 - >多线程调试DLL(/ MDd)

在构建解决方案时,它仍然会给我以下错误:

1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

我的问题是为什么Win32项目正在生成MFC错误,我该如何删除此错误.请指导我.

小智 39

在Visual Studio 2011上,这对我有用:

Project -> "project" Properties -> Configuration Properties -> C/C++ -> Advanced -> Show Includes:YES(/showIncludes)

Project -> "project" Properties -> Configuration Properties -> General -> Project Defaults -> Use of MFC :Use MFC in a shared DLL

  • 任何人都可以解释我为什么这个答案被投票而另一个没有?"在共享DLL中使用MFC"添加了/ D"_AFXDLL",因此它以更加神秘(微软)的方式完全相同.我不知道/ showIncudes是如何与这个问题相关的...... (5认同)
  • 没有必要添加 /showIncludes 标志,但感谢您指出使用 MFC 设置。 (3认同)

小智 13

我有同样的问题,但只有当我意识到我必须为调试和发布配置设置"在共享DLL中使用MFC"标志时才解决它(我只设置它用于调试).


ing*_*nti 9

根据我的经验,这是一个双向的步骤.假设您想要STATIC链接:a)设置" 在静态库中使用MFC "b)在stdafx.h中添加:#define _AFXDLL 1

适用于VS 2012