How can I compile a MATLAB Engine Fortran application using Microsoft Visual Studio 2008, Intel Visual Fortran 11.1 and MATLAB 7.10 (R2010a)?

1 view (last 30 days)
I would like to call MATLAB from my Fortran application using the MATLAB Engine interface. However, I would like to compile my project in the Microsoft Visual Studio 2008 environment and not in MATLAB 7.10 (R2010a).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Nov 2011
To compile a MATLAB Engine Fortran application in the Microsoft Visual Studio 2008 environment, perform the steps outlined below:
1. Set up a project in Visual Studio as follows:
a. Open Microsoft Visual Studio and navigate to 'File' -> 'New' -> 'Project'.
b. Select 'Intel Visual Fortran' -> 'Console Application' -> 'Empty Project'.
c. Following this, enter the name of the project and its location in the indicated text areas and click OK.
2. Add 'fengdemo.F' to the project
a. Copy the file 'fengdemo.F' to the folder where you created the Visual Studio project. This file may be obtained from the following location:
$MATLABROOT/extern/examples/eng_mat
where $MATLABROOT is the MATLAB root directory, and may be determined by entering the command:
>> matlabroot
at the MATLAB command prompt.
b. In Visual Studio, right-click on the 'Source Files' folder in the 'Solution Explorer' and click 'Add' -> 'Existing Item...'.
c. Select 'fengdemo.F' and click 'Add'.
4. Right click on the project name and select 'Properties' in the solution explorer to open the project
properties. Once this window has opened, make the following changes:
a. Under 'Fortran' -> 'General', add the directory
$MATLABROOT\extern\include
to the field 'Additional Include Directories'.
b. Under 'Fortran' -> 'Preprocessor', choose 'Yes(/fpp)' for 'Preprocess Source File'.
c. Under 'Linker' -> 'General', add the directory
$MATLABROOT\extern\lib\win32\microsoft
to the 'Additional Library Directories' field.
d. Under 'Linker' -> 'Input', add the following names:
libmx.lib
libmat.lib
libeng.lib
to the 'Additional Dependencies' field.
e. Click on 'Ok'.
5. You should now be able to build the project.
6. To run the executable, you may have to add the folder where MATLAB executable is saved to the system path. In a DOS command prompt:
set PATH=$MATLABROOT\bin\win32;%PATH%
Note: If you are compiling a 64-bit application, change any reference to 'win32' above to 'win64'. You will also have to change your target Platform to x64 in the Configuration Manager for your Visual Studio project.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!