Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 includes MFC even though empty console application is specified (C++)

I've spent most of my day trying to figure out why this error is occurring but it continues to mystify me.

I created a console application in Visual C++ and specified it to be empty. After putting all of my source in the virtual folder and compiling it an error occurred:

c:\program files\microsoft visual studio 10.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]

c:\program files\microsoft visual studio 10.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]

c:\program files\microsoft visual studio 10.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]

Strange error indeed, because I never included any MFC files. So I remedied the situation by specifying "/MT" in the code generation settings.

This worked well...until I decided to include "Windows.h", which spawned this error:

c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxv_w32.h(16): fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include windows.h

c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxv_w32.h(16): fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include windows.h

I've tried everything I could think of, including recreating the project with and without precompiled headers, a Win32 app rather than console, and a WxWidget app. All of these apps seemingly try to include MFC even though I never specified. Can anyone shed some light on this problem? Thank you!

like image 899
Dr.Mcninja Avatar asked May 14 '11 03:05

Dr.Mcninja


3 Answers

Find out what's including the MFC headers - the /showIncludes option may help with that.

Which in the IDE project property page is under:

C/C++ | Advanced | Show Includes

Once you know who is including them you can make a decision on how to address the problem - you might simply be able to remove an errant #include, but it might require jettisoning a library you're using that's dependent on MFC.

like image 97
Michael Burr Avatar answered Nov 03 '22 10:11

Michael Burr


Make sure 'USE of MFC' is in 'Use MFC in a Shared DLL' setting. That fixed it for me.

like image 45
John Councill Avatar answered Nov 03 '22 10:11

John Councill


If MFC is required, set the following values ( Debug/Win32 ):

Configuration Properties > General :

Use of MFC : Use MFC in a Shared DLL

Configuration Properties > C/C++ > Code Generation :

Runtime Library : /MDd

If MFC is not required, and only standard window libraries are required, keep the setting as below.

Configuration Properties > General :

Use of MFC : Use Standard Windows Libraries

Configuration Properties > C/C++ > Code Generation :

Runtime Library : /MTd

like image 24
Akaanthan Ccoder Avatar answered Nov 03 '22 10:11

Akaanthan Ccoder