Ask Google. Find:
- http://www.mathworks.com/matlabcentral/fileexchange/27151-writing-matlab-cmex-code
- http://www.mathworks.com/help/techdoc/matlab_external/f12977.html
- http://www.mathworks.com/support/tech-notes/1600/1622.html
Look at the examples shipped with Matlab:
cd(fullpath(matlabroot, 'extern', 'examples');
ls
And look in the documentation:
docsearch mex