MATLAB: Fatal error C1189 when compiling C++ (VS2013) program in Matlab2015a(32-bit)

c++ mixed programmingerror c1189

Hello, I am using Matlab2015a(32-bit) to compile C++ program to mex file. The compiler is Microsoft visual C++ 2013 Professional.
The code could be compiled successfully in VS2013 but error occurred when compiled it in Matlab. The error message is:
C:\Exp softwares\VS2013\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].
Similiar error occurred when I firstly compiled it in VS2013. After I set "Use of MFC" to "Use MFC in a shared DLL" in the property of the project, the problem solved in VS, but not in Matlab.
The code called external dll file to realize the function of data collection from a peripheral hardware. I want to use the port of the mex function to transfer data into Matlab to do futher online analysis.
Please let me know any way that could help me to fix this error. Thank you very much!

Best Answer

Problem solved with command in Matlab: mex -D_AFXDLL -D_UNICODE MEX_EEG_Recording2.cpp
Hope this will be helpful.
Related Question