MATLAB: How to compile a MEX file from a source file that is not located in the current working directory

c codecompilationcompilingenvironmentg++MATLABmexmexingoutsidev

I am able to compile my MEX file (myMexFile.c) present in the current working directory successfully using the MEX command.
However when I attempt to compile the same MEX file after moving it to a different location on my system using the following command:
mex myMexFile.c
I receive the following error message:
C:\PROGRA~2\MATLAB\R2007B\BIN\MEX.PL: Error: 'myMexFile.c' not found.
??? Error using ==> mex at 208
Unable to complete successfully.

Best Answer

It is possible to compile source MEX files located in any folder on your system. To do this, you would have to specify the full path to the source file. For example, if your current working directory is
C:\matlab\work
and your source file (mexMexFile.c) is present in
C:\test
execute the MEX command as shown below to compile this file.
mex C:\test1\myMexFile.c
The output MEX file will be created in your current working directory.