error Please #define _AFXDLL or do not use /MD[d] occurs even after making changes in Project Properties
Asked Answered
V

9

59

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)

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]

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

Violent answered 30/7, 2014 at 7:25 Comment(6)
Why don't you just do what it says and #define _AFXDLL? C/C++, Preprocessor, Preprocessor Definitions setting.Ossein
Look at the build log file - make sure there's a /D _AFXDLL in the command line issued for the compile. The "Use MFC in a shared DLL" should cause that to happen. Maybe a clean/rebuild might help? Also, VC++11 is Visual Studio 2012.Bridging
Thanks Hans Passant. I have added _AFXDLL in the Preprocessor definitions. But it still gives the same error.Violent
What is the project type? (dll? static lib? exe?)Eastwards
Check what Michael said: in the build log, is there a _AFXDLL? Do not define it manually, it is added when you set "Use MFC in a shared DLL". If it is set there, this sounds like a stale preprocessed header thing. Manually delete everything that is not a source file, project file or resource and build again.Pliny
The project on which I am working has its own method of building a solution. So I am not able to check build log.Violent
W
57

On Visual Studio 2011, this worked for me:

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

(In Visual Studio 2019, the latter setting can be found in "Properties -> Configuration Properties -> Advanced -> Use of MFC"

Wilful answered 30/3, 2015 at 12:2 Comment(5)
Can anyone explain me why is this answer upvoted and the other one not? "Use MFC in a shared DLL" adds /D "_AFXDLL" so it does exactly the same in a more cryptic (microsoft) way. And I have no clue how does /showIncudes relate to the issue...Extol
It is not necessary to add the /showIncludes flag, but thanks for pointing out the Use of MFC setting.Bettyebettzel
Additionally, the author of the post said that he already set the project properties to use MFC in a shared DLL but it did not resolve the error. Frankly, none of the answers actually answer the original question.Kele
/showIncludes will print all of the files being included. Source: learn.microsoft.com/en-us/cpp/build/reference/…Fleury
Thank you for pointing out that /showIncludes was unnecessary to resolve this.Wilful
P
17

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).

Photogrammetry answered 3/8, 2016 at 21:20 Comment(0)
C
14

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

works on VS 2012

Cynara answered 25/9, 2017 at 16:12 Comment(0)
P
4

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.

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.

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.

Pessimism answered 13/2, 2018 at 13:39 Comment(0)
P
2

I was getting this error because I did not properly set the configuration of the project to "Use MFC in a Shared DLL". My mistake was that I set this option only for Release mode and when I compiled in Debug mode I got this error. Applying the settings for both the Debug & Release mode configuration solved the problem for me.

Following was the settings:

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

Pupiparous answered 7/12, 2018 at 10:8 Comment(0)
S
2
  1. Open

    Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library

  2. Select Multi-threaded (/MT) in Runtime Library Section.

This will remove your error. Enjoy.

Stenotypy answered 9/8, 2019 at 9:41 Comment(0)
V
1

I have also faced the same error. The error message is self explanatory.

You need to add #define _AFXDLL in your AFX.h file.

Veridical answered 20/10, 2019 at 16:29 Comment(0)
V
0

For me, the target had to be changed from x64 to x86.

Villager answered 30/8, 2019 at 14:8 Comment(0)
S
0

I have also had this problem using vs2019. For me, a better way to state the path, I think, is: project -> properties -> configuration (which opens automatically after clicking on properties) and then -> advanced -> mfc. It really threw me for a while when I clicked on properties and then could not find "configuration properties" until I noticed the advanced in the list already on the screen.

Stamps answered 12/1, 2022 at 15:39 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wiser

© 2022 - 2024 — McMap. All rights reserved.