在Matlab命令行使用mex命令时出现错误:error:Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
为解决这个问题尝试了很多办法,最后发现最简单的办法就是按照错误提示,去找到afx.h头文件(我的路径是C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\atlmfc\include\afx.h,不想找路径可以直接用everything查找,很方便),在里面添加#define _AFXDLL,添加位置如下图所示:
像这样添加成功后保存文件,再使用mex指令就不会报错了,可以正常运行,如下图所示。