MATLAB: How to create Fortran MEX-files using the Watcom Fortran Compiler 11.0

ccompilecrossfortranlanguageMATLABmexwatcom

I am trying to use the Watcom Fortran compiler to create MEX-files.

Best Answer

We do not support the Watcom Fortran compiler. Check the following link for a list of the compilers that we support:
However, the following are some guidelines that may be adopted to create Fortran MEX files using the Watcom Fortran compiler 11.0 and a C-MEX gateway function.
NOTE: This information was sent in to us by a customer and we only recommend this as a reference. This has not been tested by, and therefore is not supported by, MathWorks.
1. Use the "aux" pragma in the C-MEX gateway routine, as described in the Watcom Fortran Programmer's guide under "Mixed Language Programming". This pragma converts calling conventions from C to Fortran and vice versa.
2. MEX routines use stack-based argument passing, as opposed to register-based argument passing. This means that both the C-MEX gateway routine and the Fortran routines must be compiled in this mode. The corresponding compiler options are -3s for Watcom C/C++ and /sc for Watcom Fortran, respectively.
3. Both the C-MEX gateway and the Fortran files must be compiled as "dynamic link library".
Option /bd for both versions.
4. When creating the MEX function using the MEX command, put a Fortran .obj file first. That way, the MEX-file will have the same name as the Fortran .obj file.
5. When creating the MEX function, use the Watcom C/C++ 11.0 options file (wat11copts.bat). However, when you do this, all paths and environment variables are set to the C/C++ compiler. This means that during linking, the Fortran libraries, referred to by the Fortran .obj file(s), are not found. Therefore, place these in your working directory. (It seems that you only need to do this for "flib7s.lib")
The MATLAB Central news-group is also a useful resource for information regarding this process:
http://www.mathworks.com/matlabcentral
Related Question