MATLAB: Do I not get a PDB file when building a MEX function with the -g option

MATLAB

I build a MEX function with the -g option:
>> mex g filename.c
It produces a MEXW64 file but not a PDB.
I need the PDB file for debugging in Visual Studio.

Best Answer

Whether a PDB file is created or not depends on the compiler that is used when you mexed your C/C++ code. If you are using Microsoft Visual Studio or WIndows SDK 7.1, you will get this PDB file.
But MinGW or MinGW64 do not produce it. Note that debugging works anyway, since MinGW just does not produce the debug info in the same way. This is not a limitation on our side, but on the side of the compilers.
This post on MATLAB Answers explains how to debug MEX files compiled with MinGW64 and -g flags:
If you want to use it in Visual Studio you need to build the MEX function using the same compiler. Using SDK 7.1 might work (since it produces a PDB file as well) but it is not recommended.