Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

Incorporating Fortran functions into Matlab

What is wrong with trying to use the .MEX method of incorporating Fortran functions into Matlab as subroutines?

The problem is that Mathworks does not load the libraries in a way that all symbols can be resolved.

Work around:

  1. Set environment variable LD_LIBRARY_PATH whenever running
    1. /usr/opt/bin/matlab (4.2c)
    2. /usr/opt/bin/fmex (4.2c)
    3. /usr/opt/bin/cmex (4.2c)
      1. csh and relatives setenv LD_LIBRARY_PATH /usr/opt/lib
      2. sh and relatives LD_LIBRARY_PATH=/usr/opt/lib export LD_LIBRARY_PATH

  2. /usr/opt/bin/fmex (4.2c). When compiling using fmex, you must force the linker to search the math library, /opt/SUNWspro/SC2.0.1/libm.a, twice in order to resolve all the symbols. The way to do this is to invoke fmex as follows: fmex func.f LD_FCLIBS='$LD_FCLIBS /opt/SUNWspro/SC2.0.1/libm.a

    [Note: The script fmex itself sets LD_FCLIBS = -lM77 -lF77 -lm before it appends the command line values.]

  3. /usr/opt/bin/cmex (4.2c). Probably needs to be done the same way as fmex. There is no test case.

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: Mar 7, 2007 11:53 am US/Eastern by admin
JumpURL: