daveb
09-02-2003, 11:10 PM
The key thing I had to add to the link statement was a -Wl,-E (export all
dynamic symbols). This was not required for 6.1, only for 6.2. Using
a temporary library of the extra *.o files from the lf95 linking
was also helpful. Here is a short writeup:
To compile a mex function make sure that mexsh.opts (discussed below)
is either in the same directory or in your login directory, then
>> mex dumb.f
This will produce the mex function file dumb.mexglx See the matlab
documention on how to interface mex calls with fortran. You will probably
need to use fortran 77 compliant code for the interface routine (which, in
any case, should do very little but call your own routine), your own code
should be able to use fortran 90 & 95 code.
Using libraries with mex functions is VERY tricky. You'll have to
modify the FLIBS routines (libraries will be HAVE to be compiled with
the lf95 options --ml cdecl to work) definition in the mexopts.sh
file.
Here are my default mexopt.sh options:
FC='lf95'
FFLAGS='--wide --ml cdecl --sav'
FLIBS='$RPATH $MLIBS -Wl,-E -Wl,-m,elf_i386
-Wl,--rpath-link,/usr/local/lf9562/lib -lfj9i6 -lfj9f6 -lfj9e6 -lfccx86_6a
-Wl,-L/someplace/matcode/lf95_mex -ltemp -lelf -llinux -lc -lm'
FOPTIMFLAGS='-O'
FDEBUGFLAGS='-g'
The libtemp.a library contains the routines
/usr/lib/crt1.o
/usr/local/lf9562/lib/fj90rt0.o
/usr/lib/crtn.o
which are required, but seem to like to be in library when used with
matlab. To create the library I copied the routines to a directory lib/
and used the command:
ar cr /someplace/matcode/lf95_mex/libtemp.a lib/*.o
The elf and linux libraries are also required and normally are in
the system area, but I placed logical links in the same work directory
as the temp library to simplify matters (this won't be required on most
systems).
David
--
Dr. David G. Long
Director, BYU Center for Remote Sensing
dynamic symbols). This was not required for 6.1, only for 6.2. Using
a temporary library of the extra *.o files from the lf95 linking
was also helpful. Here is a short writeup:
To compile a mex function make sure that mexsh.opts (discussed below)
is either in the same directory or in your login directory, then
>> mex dumb.f
This will produce the mex function file dumb.mexglx See the matlab
documention on how to interface mex calls with fortran. You will probably
need to use fortran 77 compliant code for the interface routine (which, in
any case, should do very little but call your own routine), your own code
should be able to use fortran 90 & 95 code.
Using libraries with mex functions is VERY tricky. You'll have to
modify the FLIBS routines (libraries will be HAVE to be compiled with
the lf95 options --ml cdecl to work) definition in the mexopts.sh
file.
Here are my default mexopt.sh options:
FC='lf95'
FFLAGS='--wide --ml cdecl --sav'
FLIBS='$RPATH $MLIBS -Wl,-E -Wl,-m,elf_i386
-Wl,--rpath-link,/usr/local/lf9562/lib -lfj9i6 -lfj9f6 -lfj9e6 -lfccx86_6a
-Wl,-L/someplace/matcode/lf95_mex -ltemp -lelf -llinux -lc -lm'
FOPTIMFLAGS='-O'
FDEBUGFLAGS='-g'
The libtemp.a library contains the routines
/usr/lib/crt1.o
/usr/local/lf9562/lib/fj90rt0.o
/usr/lib/crtn.o
which are required, but seem to like to be in library when used with
matlab. To create the library I copied the routines to a directory lib/
and used the command:
ar cr /someplace/matcode/lf95_mex/libtemp.a lib/*.o
The elf and linux libraries are also required and normally are in
the system area, but I placed logical links in the same work directory
as the temp library to simplify matters (this won't be required on most
systems).
David
--
Dr. David G. Long
Director, BYU Center for Remote Sensing