How do I create a MEX file
Solution Number: 31087
Date Last Modified: 2003-12-10
Product: MATLAB 6.1 ==> Current Version
Platform: Information Not Available
How do I create a MEX file using the Microsoft Developer Studio and Compaq Visual Fortran 6.5?
The documentation in the External Interfaces Guide outlines the procedure to do the above in the Visual C++ environment. This document outlines this procedure for Fortran programs in the MSDev IDE.
Compiling MEX-Files with the MSDEV IDE for Compaq Visual Fortran 6.5:
To build MEX-files with the MSDEV IDE for Compaq Visual Fortran 6.5:
1. Inside the IDE, go to FILE-->NEW. Select "Fortran Dynamic Link Library". Provide a project name. In the event you do not see this option, please check the installation of Compaq Visual Fortran. There should be an .awx file that should be installed by Compaq Visual Fortran. If not check with Compaq for troubleshooting.
2. Create an empty DLL project.
3. Once the project is created, add the files yprimefg.F and yprimef.F from the $MATLAB/extern/examples/mex/ directory to your project. Here, $MATLAB refers to the root MATLAB directory on your computer.
4. Create a file with extension .DEF and add it to the project (anywhere should be fine; resources for example). The .DEF file should have the following text (if your project name is myproj, then a dll will be created called myproj.dll, used below):
5. Select the menu Project-->Settings... Here, under Fortran, please change the following:
a. Category: Fortran Language
Source Form: Force fixed form
Fixed form length: 80 columns
b. Category: External Procedures
External Name Interpretation: Upper case
Argument Passing convention: Default
String Length Argument Passing: After All Args
a. Category Input:
Add these libraries to Object/library modules: libmx.lib libmex.lib libmat.lib ....
Additional library path: <MATLAB>/extern/lib/win32/microsoft/msvc60
6. The above should compile and run and can be run as a MEX file in MATLAB.
We expect that similar steps are performed for Compaq Visual Fortran 6.6. It is not practical, however, for us to offer complete technical support on the details of using any specific one of the large number of IDE environments our customers use. If you need detailed assistance with the particular settings needed to get your IDE environment to generate code that successfully compiles and runs with our products, we suggest you contact the manufacturer of your IDE to get information or expert technical assistance in using it.