完整报错如下:
D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\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]
NMAKE : fatal error U1077: “D:\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx86\x86\cl.exe”: 返回代码“0x2” Stop.
NMAKE : fatal error U1077: “"D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2” Stop.
NMAKE : fatal error U1077: “"D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2” Stop.
NMAKE : fatal error U1077: “"D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"”: 返回代码“0x2” Stop.
报错原因未配置好CMakeLists.txt,需在其中添加如下内容:
set_target_properties(MFCBase PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
target_compile_definitions(MFCBase PRIVATE
-DWIN32
-D_DEBUG
-D_WINDOWS
-D_VC80_UPGRADE=0x0600
-D_UNICODE
-DUNICODE
-D_AFXDLL)
target_link_options(MFCBase PRIVATE
/ENTRY:wWinMainCRTStartup)
图中红色部分需替换成项目启动cpp文件名。
配置完成后,重新启动,正确运行!