How do I compile Fortran code that uses the MATLAB Engine API with Intel Fortran compilers?

I am trying to run a Fortran application that uses the MATLAB Engine API for Fortran. I am using the Intel oneAPI for Fortran compiler. What commands can I run to compile my application from the system command line?

 Accepted Answer

To only compile the file (i.e. create only the object file, no linking), call the compilation command with preprocessing enabled and include the "matlabroot\extern\include" directory.
For example, for some Windows systems, this may look like: 
/fpp matdemo1.F /I"matlabroot\extern\include" /c
where 
  • /fpp runs the preprocessor on all source files before compilation.
  • matdemo1.F is the file to be compiled.
  • /I includes the specified directories.
  • /c prevents linking, causing the compilation to stop once the object file is generated.
The syntax of these commands is specific to both OS and compiler version, so consult official Intel documentation for the proper syntax for your configuration. 
To both compile and link in one command
(i.e. generate an executable), call the compilation command as above and link the "libeng" and "libmx" libraries from the appropriate directory. 
For example, for some Unix systems, this may look like:
-fpp matdemo1.F -I"matlabroot\extern\include" -L"matlabroot\extern\lib\<your OS here>" -leng -lmx
where 
  • -L specifies the directory to search first for libraries (optional but helps to ensure the correct libraries are linked).
  • -leng specifies to link the library "libeng".
  • -lmx specifies to link the library "libmx".
Again, please note that these options are specific to the operating system used and adjust the syntax accordingly. Windows systems will typically automate linking, causing some of these commands to not be available for these systems.
For more information on syntax and additional compiler options, refer to the official Intel documentation: 
 

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!