在项目属性发生更改后,请定义_AFXDLL或不使用/MD[d]。

时间:2022-09-01 13:34:57

I am working on Win32 project in Visual Studio 2011. It is generating MFC error when I includes afx.h or afxwin.h. To resolve this, I have made the following changes in the Project Properties tab : 1) Use of MFC : Use MFC in a shared DLL 2) C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug DLL(/MDd)

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

Still it gives me following error when I build the solution :

当我构建解决方案时,仍然会有以下错误:

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]

1>C:\程序文件(x86)\ microsoftvisualstudio 11.0\vc\atlmfc\包括\ \afx.h(24):致命错误C1189: #error:构建MFC应用与/MD[d] (CRT dll版本)需要MFC共享dll版本。请#define _AFXDLL或不使用/MD[d]

My question is why Win32 project is generating MFC error and how should I remove this error.Kindly guide me.

我的问题是为什么Win32项目会产生MFC错误,我应该如何删除这个错误。请指引我。

5 个解决方案

#1


30  

On Visual Studio 2011, this worked for me:

在Visual Studio 2011中,这对我有帮助:

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

项目->“项目”属性->配置属性-> - C/ c++ ->高级->展示包括:YES(/ showinclude)

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

项目->“项目”属性->配置属性->通用->项目默认->使用MFC:在一个共享DLL中使用MFC。

#2


10  

I had the same problem, but only solved it when I realized I had to set the "Use MFC in a shared DLL" flag for both debug and release configurations (I had only set it for debug).

我遇到了同样的问题,但只有当我意识到我必须在“共享DLL”标志中设置“使用MFC”来调试和释放配置时,才解决了这个问题(我只是将它设置为debug)。

#3


2  

In my experience is a two ways step. suppose You want STATIC linking: a) set "Use MFC in a Static Library" b) add: #define _AFXDLL 1 in stdafx.h

在我的经验中有两种方法。假设您想要静态链接:a) set“在静态库中使用MFC”b) add: #define _AFXDLL 1在stdafx.h中。

works on VS 2012

在VS 2012

#4


1  

I struggled with a similar problem. In my case it was caused by the settings that were attached to individual cpp files. Since they contained preprocessor symbols, they actually blocked the project (or props) level settings that utilize preprocessor symbols.

我也遇到过类似的问题。在我的例子中,它是由附加到单个cpp文件的设置引起的。由于它们包含预处理器符号,所以它们实际上阻塞了利用预处理器符号的项目(或道具)级别设置。

So check if you have file level settings in your vcxproj. If you do, check if they are equal to the project level settings. If they are, you can safely remove them. If there are differences, you have to sort that out.

因此,检查您的vcxproj中是否有文件级别设置。如果您这样做,检查它们是否等于项目级别设置。如果是的话,你可以放心地把它们拿走。如果有区别的话,你必须把它分类。

Cpp file level settings should usually be empty (there are some exceptions when you need them), but it is quite easy to add them by accident.

Cpp文件级别的设置通常应该是空的(当您需要的时候有一些异常),但是很容易将它们添加到意外中。

#5


-4  

Add the #define _AFXDLL indirectly by a project configuration settings

通过项目配置设置间接添加#define _AFXDLL。

#1


30  

On Visual Studio 2011, this worked for me:

在Visual Studio 2011中,这对我有帮助:

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

项目->“项目”属性->配置属性-> - C/ c++ ->高级->展示包括:YES(/ showinclude)

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

项目->“项目”属性->配置属性->通用->项目默认->使用MFC:在一个共享DLL中使用MFC。

#2


10  

I had the same problem, but only solved it when I realized I had to set the "Use MFC in a shared DLL" flag for both debug and release configurations (I had only set it for debug).

我遇到了同样的问题,但只有当我意识到我必须在“共享DLL”标志中设置“使用MFC”来调试和释放配置时,才解决了这个问题(我只是将它设置为debug)。

#3


2  

In my experience is a two ways step. suppose You want STATIC linking: a) set "Use MFC in a Static Library" b) add: #define _AFXDLL 1 in stdafx.h

在我的经验中有两种方法。假设您想要静态链接:a) set“在静态库中使用MFC”b) add: #define _AFXDLL 1在stdafx.h中。

works on VS 2012

在VS 2012

#4


1  

I struggled with a similar problem. In my case it was caused by the settings that were attached to individual cpp files. Since they contained preprocessor symbols, they actually blocked the project (or props) level settings that utilize preprocessor symbols.

我也遇到过类似的问题。在我的例子中,它是由附加到单个cpp文件的设置引起的。由于它们包含预处理器符号,所以它们实际上阻塞了利用预处理器符号的项目(或道具)级别设置。

So check if you have file level settings in your vcxproj. If you do, check if they are equal to the project level settings. If they are, you can safely remove them. If there are differences, you have to sort that out.

因此,检查您的vcxproj中是否有文件级别设置。如果您这样做,检查它们是否等于项目级别设置。如果是的话,你可以放心地把它们拿走。如果有区别的话,你必须把它分类。

Cpp file level settings should usually be empty (there are some exceptions when you need them), but it is quite easy to add them by accident.

Cpp文件级别的设置通常应该是空的(当您需要的时候有一些异常),但是很容易将它们添加到意外中。

#5


-4  

Add the #define _AFXDLL indirectly by a project configuration settings

通过项目配置设置间接添加#define _AFXDLL。