#Error Please Use the /Md Switch for _Afxdll Builds

Unexplainable error Please use the /MD switch for _AFXDLL builds

_AFXDLL is never used with a static MFC build! _AFXDLL.

_AFXDLL is only set when the shared MFC builds are used.

Also static MFC build implies a static CRT.

What does preprocessor `_AFXDLL` mean?

MSVC++ provides an optimization for programmers that want to deploy only a single executable file. You can build with /MT to link the C runtime library and the standard C++ library into the EXE. And you can link the static MFC libraries to link MFC into the EXE. Not uncommon for small LOB apps.

Nice, but that cannot work properly when you also use DLLs to modularize or share your code or favor faster build times. MFC (and the CRT) have lots of global state, the CWinApp singleton is a good example. A C++ program does not run in a VM like Java or C# apps do, one of the modules has to take responsibility to store that global state. And the other modules must use that module's globals, not their own. So you must use the DLL version of MFC and the DLL version of the C and C++ runtime libraries, and link their import libraries, they take on that responsibility.

And you have to tell the compiler about it, so that the library will go looking for the right place for those globals. That requires #defining _AFXDLL. Read it like "the application framework lives in its own DLL". The CRT has a macro for that as well, it is _DLL.

Do note that this is completely automatic in the IDE. Project > Properties > General, "Use of MFC" setting. If you pick "Use of MFC in a Shared DLL" for this setting then you automagically will also get _AFXDLL defined. Same for the CRT.

Can't add function to MFC ActiveX

Visual Studio is running with a user that does not have permission to run regsvr32, which attempts to register the component after a successful build.

You can get around this by running Visual Studio as Administrator.

As for the 2nd error

#error Please use the /MD switch for _AFXDLL builds

Actually, I had to switch to another /Mx setting, and then switch back so the selection was in bold, it seems the IDE isn't updating properly.

Migrating VS 2008 project to 2012, compiles, Unable to start program

Ended up having to install the ultimate version of VS.



Related Topics



Leave a reply



Submit