Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

help calling matlab functions

cfox28
Beginner
1,116 Views
Hi
I am trying to call matlab functions within a fortran code.
for opening and closing .mat files. However I do not know how to
make the fortran compiler use the matlab libraries such as
libmx.lib libmat.lib libeng.lib so the fortran code
will compile and use "engOpen", "engPutVariable"etc
can anyone explain how to do this baring in mind that I am
new to fortran
Cheers
CHRIS
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,116 Views
There are a couple of ways to do it. I assume you are using the visual development environment?

The simplest way, and one I recommend, is to right click on the Source Files folder in the Solution Explorer pane, select Add..Files..Existing files. Browse to the folder containing the libraries and select them to add them to the project. You may need to change the "Files of type" setting to show all files.

Another way is to add the library names to the Linker property page for additional dependencies including the full path.

If you are using the command line, just give the path to the libraries on the ifort command line along with other files or objects.
0 Kudos
cfox28
Beginner
1,116 Views

Thanks steve

I tried those methods but still get the same error LNK2019:unresolved external

symbol _ENGOPEN. I am wondering if the _ in the fortran output error

will be causing a problem as it isn't in the matlab library like that, its just

ENGOPEN

Thanks CHRIS

0 Kudos
Steven_L_Intel1
Employee
1,116 Views
The underscore is added by the compiler, so while the documentation may say ENGOPEN, the routine in the library would be called _ENGOPEN.

Are you perhaps using a MATLAB library that was built for use with Compaq Visual Fortran? If so, you will need to change the calling conventions to match CVF. The simplest way to do this is to go to the Fortran project properties, External Procedures, and change argument passing convention to CVF and string length argument passing to "after individual string arg". Then rebuild your application.
0 Kudos
cfox28
Beginner
1,116 Views

Steve

That worked thanks very much for the help

CHRIS

0 Kudos
mshossain
Beginner
1,116 Views
Hi,
I have a similar problem. I am using intel fortran in linux. I am trying to connect with matlab engine from fortran. Would you please let me know the solution for intel fortran? I was able to connect to matlab with g95 compiler. I need to run it using ifort.


A part of the errors I get are as follows:

/tmp/ifortMjMc0U.o: In function `MAIN__':
fengdemo.f:(.text+0x49): undefined reference to `engopen_'
fengdemo.f:(.text+0x76): undefined reference to `mxcreatedoublematrix_'
fengdemo.f:(.text+0x8d): undefined reference to `mxgetpr_'
fengdemo.f:(.text+0xae): undefined reference to `mxcopyreal8toptr_'
fengdemo.f:(.text+0xca): undefined reference to `engputvariable_'
fengdemo.f:(.text+0xec): undefined reference to `engevalstring_'
fengdemo.f:(.text+0x10b): undefined reference to `engevalstring_'
--------------------

Thank you.
0 Kudos
mecej4
Honored Contributor III
1,116 Views
Whether it is possible and how to link IFort and Matlab can depend on which versions of Intel Fortran and Matlab you are working with. You did not provide any information on the versions.

Rejuvenating a five-year-old thread instead of starting anew is not a good idea, unless the compiler and Matlab versions you want to use now match the versions which the originator of the thread used.
0 Kudos
Reply