Compiling mex with gfortran

12 views (last 30 days)
Lukas Bystricky
Lukas Bystricky on 27 Mar 2020
I'm trying to compile some Fortran files into a mex file. I'm using an existing makefile, and I'm having issues linking the correct libraries with gfortran. The original makefile used the Intel compiler, with the libraries
MEXLIB = -lifcore -lirc -lsvml -limf -lgfortran -liomp5
I was able to find those libraries (replacing l with lib) in the matlab sys/os/glnxa64 directory, so I set the MEXLIBDIR to that. When I run make I get the following error:
/usr/bin/ld: cannot find -libifcore
/usr/bin/ld: cannot find -libirc
/usr/bin/ld: cannot find -libsvml
/usr/bin/ld: cannot find -libimf
/usr/bin/ld: cannot find -libgfortran
/usr/bin/ld: cannot find -libiomp5
collect2: error: ld returned 1 exit status
makefile:25: recipe for target 'mex' failed
How can I get gfortran to locate these libraries (if these are the correct ones)?
I'm running Matlab r2018a on Ubuntu 16.04 LTS.
Here's the (slightly simplified) makefile after I've edited it:
FORTRAN = gfortran
FFLAGS = -c -fpic -openmp -O3
MEXLIBDIR = /opt/matlab/r2018a/sys/os/glnxa64
MEXLIB = -libifcore -libirc -libsvml -libimf -libgfortran -libiomp5
all: file_a mex
mex: file_b.F $(OBJS)
$(MEX) -v -compatibleArrayDims -O file_b.F $(OBJS) -L$(MEXLIBDIR) $(MEXLIB)
file_a: file_a.f
$(FORTRAN) $(FFLAGS) file_a.f

Answers (0)




Community Treasure Hunt

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

Start Hunting!