[Solved] Error C1189: #error: Please use the /MD switch for _AFXDLL builds

An error occurred when compiling the program in VS 2013:

Error message 1:

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]

Reason :

The conventional one is: use MFC in the static library, or use the standard Windows library, at this time, no matter what it is, an error may be reported.

The multi-threaded debugging in the runtime library is: MDd (multi-threaded debugging DLL)

Solution :

Change MDd to MTd. If error 2 is reported after correction, change it as follows.

 

Error message 2:

error C1189: #error: Please use the /MD switch for _AFXDLL builds 

Reason :

The conventional one is: use MFC in a shared DLL,

The multi-threaded debugging in the runtime library is: MTd (multi-threaded debugging)

Solution :

Change the general to: use MFC in the static library, or use the standard Windows library

 

Conventional and runtime libraries are as follows:

General: Right-click the project -> Properties -> Configuration Properties -> General, and then select “Use MFC in a static library” in the “Use of MFC” option in the “Project Defaults” on the right,

Multi-threaded debugging: Right-click the project–>Properties->Configuration Properties->c/c++->Code Generation->Runtime Library->Multithreaded Debugging (/MTd)

 

Related notes:

There are three settings for the use of MFC : 

 1. Use standard Windows libraries

 2. Use MFC in the static library: it is to write the relevant code in the DLL into the EXE file, the file is larger, but it can be run on the machine without the relevant DLL;

 3. Use MFC in a shared DLL: It means that the content of some MFC DLLs is not included in the EXE file when packaging, so the EXE file is small, but the system requires related DLL files at runtime;

Multi-threaded debugging

/MD: Use multithreading in the dll to create the release version of the dynamic link library, which needs to be selected.

/MT: Use multithreading in exe to create a release version of exe, which needs to be selected.

/MTd: Same as /MT, but used in the Debug version.

/MDL: Same as /MD, but used in the Debug version.

 

If it is Debug’s “Use MFC in a static library”, don’t use MDd, use MTd instead, and then compile it to pass.

If it is Debug’s “Use MFC in shared DLL”, be careful not to use MTd, use MDd instead;

If it is the Release version “use MFC in static library”, don’t use MD, use MT;

If it is the Release version of “Use MFC in a shared DLL”, do not use MT, use MD.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *