| Mohammad 2006-01-12, 7:58 am |
| Calling Matlab from G95 code
Matlab lets third party programs call its routines through Matlab
External Interface.
I try to use Matlab engine in a G95 (Fortran 95 compiler) code. I use
G95-MinGW32 under Windows XP SP2.
To call Matlab engine from a G95 code, the basic three Matlab dlls
(libeng.dll, libmx.dll, libut.dll) should be linked to the G95 code. It
seems there is a problem with decoration and case sensitivity. Matlab
routines reside in dll have a special char cases like "engOpen" or
"engClose". This while G95 can be instructed only to generate the codes
with lowercase or uppercase. Linking a G95 code with Matlab dlls
generates the following error:
feng.f90:(.text+0x18): undefined reference to 'engopen'
To clear the subject I introduce here a step by step example:
1. Fortran program to Call Matlab
--------------------------------
program feng
integer engOpen
integer ep
ep = engOpen('matlab ')
if (ep .eq. 0) then
write(6,*) 'Can''t start MATLAB engine'
stop
else
write(6,*) 'MATLAB engine started'
endif
end program main
2. All matlab dlls are in the Path, now we compile the above code
under Windows XP using G95 - MinGW compiler as follows:
------------------------------------------
g95 -c -mrtd -fno-underscoring feng.f90 -o feng.o
g95 -o %1.exe -shared -L. libeng.dll %1.o
::::OUTPUTS
feng.f90:(.text+0x18): undefined reference to 'engopen'
How we can resolve this problem. Your kind help is appreciated
Aria
P.s:
- I know about GNUmex and some other methods, but they are very
complicated.
- I generated a lib interface as "lib /def:libeng.def" using the
Matlab provided "def" files but the problem was not resolved.
|