MATLAB: Compiling C and fortran files in MATLAB mex

mex

Hi i have a standalone fortran code and i have written a mex interface function to access it from MATLAB. My fortran code has one .c file named adwrite.c. When i try to compile it in MATLAB i get an error "C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: 'adwrite.c' not found. ". I have intel fortran compiler in my system. Can some one help me with this problem. Thank You in advance

Best Answer

First compile adwrite.c by itself with a C compiler to generate an object file (e.g., adwrite.obj on Windows). If you are doing it from the MATLAB command line simply add the -c option to request compile only without linking. Then compile your Fortran mex routine including the adwrite.obj file on the command (*not* the adwrite.c). Be sure adwrite.obj is in the current default directory.