MATLAB: Am I receiving an error when I try to override a mex file with the -outdir option of the mex command

MATLABmexs-function

When I try to override a mex file with the following command
mex -outdir .\sfun -I.\moduls .\sfun\mysfun.c .\moduls\modul.c
I receive the following error:
cannot open output file .\sfun\mysfun.dll:
C:\MATLAB\R14SP2\BIN\WIN32\MEX.PL: Error: link of '.\sfun\mysfun.dll' failed.
??? Error using ==> mex
Unable to complete successfully

Best Answer

This error will only occur if you try overwriting a MEX file that is currently being used by another application. This issue is not a bug and can resolved by:
(i) Ensuring that you have write permissions to the output directory.
(ii) Ensuring that the mex file is not being used by another application. You can confirm this by executing the following command:
clear mex