MATLAB: ‘Not a valid win32 application’ error – using mex files with Matlab 2011b and Visual C++ 2010 Express

MATLABmexwindows 7

Hello
I have C++ project which compiles in Visual C++ 2010 Express, which I have set as my compiler using mex -setup in MatLab R2011b, but when I try to run this mex file from an m-file in Matlab I get the following error:
Invalid MEX-file 'C:\Users\Ellen W\Documents\Visual Studio 2010\Projects\Simulate\Debug\simulate.mexw32': C:\Users\Ellen W\Documents\Visual Studio 2010\Projects\Simulate\Debug\simulate.mexw32 is not a valid Win32 application.
I followed online instructions exactly about what settings I need for the project. My computer is Windows 7 Professional, 32bit operating system.
Thank you in advance for your help!

Best Answer

Is there a reason that you don't compile directly using the "mex" command in MATLAB? The most likely issue could be that the MEX-file depends on Visual Studio redistributables (DLLs) which are not on the System path, so MATLAB is unable to load them, which is necessary to run the MEX-file. Could you try running your MEX-file through Dependency Walker and see if you can find the missing dependencies.
Related Question