How to setup gfortran on Mac OSX 10.9 and MatLab R2014a?

MatLab 2014a Mac OSX 10.9.2 Maverick Mex gfortran configuration
I'm trying to configure using mex -setup FORTRAN and I'm getting the message:
mex -setup FORTRAN Error using mex No supported compiler or SDK was found.
But I have gfortran 4.6.4 installed via fink. The website says that 4.3.x is supported, but isn't gfortran backward compatible in their revisions; therefore, 4.6.4 or even 4.8.2 (the latest for OSX 10.9 as of this posting) should work right? How does one set the fortran compiler options?
Is it best to finesse things with a higher version of gfortran or to install the exact version in the MatLab compatibility chart calls for? Why did the C and C++ portions of the gcc package work just fine and not the gfortran? What happened to the MEXOPTS.sh file in R2014a?

4 Comments

Any answer to the subquestion, "What happened to the MEXOPTS.sh file in R2014a?"
Alec, I am the product manager in this area. The infrastructure for MEX changed in 14a and .sh/bat files are no longer used; the release notes discuss some of the more user-visible changes. mexopts.sh/.bat files will still work for a release or two to ease the transition. The "new" files are XML, but we're hoping that is a technical detail few need to concern themselves with.
If you have specific need to customize .sh files, start a new question or send me a private email.
Any comment on the backward compatibility question of gfortran? I installed gcc4.3 via MacPorts which gave me "gfortran-mp-4.3." I showed mex where this was located (using the link below). The timesTwo.F example compiles and can be invoked from the MATLAB command line. However, the yprime.F example compiles but unfortunately crashes MATLAB when invoked. It would be nice to be able to use the latest available binary from the gfortran binaries page. But when I try this, I get the following error:
Error using mex Undefined symbols for architecture x86_64: "_mexfunction_", referenced from: -exported_symbol[s_list] command line option ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
and am not sure how to proceed...
Well, this is embarrassing... but fortunately I resolved the issue above. Turns out the Fortran yprime examples are dependent on TWO files. So running
mex -v yprimef.F yprimefg.F
did the trick. I cannot read Fortran but need to get some code compiled, so I hope this comment will be useful to someone in a similar situation.

Sign in to comment.

 Accepted Answer

Try:
>> mex -v <filename.f>
This will give you verbose output that should help pinpoint why MEX can't find gfortan. Copy and paste the full output into this Answer.

5 Comments

@ Ken Atwell
Thanks for reading my question. following the example on the mex page in the help files: http://www.mathworks.com/help/matlab/ref/mex.html
EDU>> copyfile(fullfile(matlabroot,'extern','examples','refbook',... 'loadsparse.F'),'.','f');
EDU>> copyfile(fullfile(matlabroot,'extern','examples','refbook',... 'fulltosparse.F'),'.','f');
EDU>> mex -v -largeArrayDims fulltosparse.F loadsparse.F
Verbose mode is on.
No MEX options file identified; looking for an implicit selection.
... Looking for compiler 'gfortran' ...
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...No.
Did not find installed compiler 'gfortran'.
Error using mex
No supported compiler or SDK was found. For options, visit
and from terminal......
XXXXXXXXXXXXXX:~ XXXXXXX$ gfortran -v
Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.4.2/4.6.4/lto-wrapper Target: x86_64-apple-darwin11.4.2 Configured with: ../gcc-4.6.4/configure --prefix=/sw --prefix=/sw/lib/gcc4.6 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.6/info --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.6 --enable-cloog-backend=isl Thread model: posix gcc version 4.6.4 (GCC)
XXXXXXXXXXXX:~ XXXXXXXXXXX$
Ok, so matlab is looking for a gfortran compiler in usr/local/bin and there is not one installed there as fink installs in the /sw directory by default. How can I change or add a path for Matlab to look? or do I have to uninstall the fink installed gfortran 4.6.4 and install a gfortran compiler in use/local/bin?
Ok, taking a guess.... installing gfortran 4.8.2 and re-running things....
EDU>> mex -v -largeArrayDims fulltosparse.F loadsparse.F Verbose mode is on. No MEX options file identified; looking for an implicit selection. ... Looking for compiler 'gfortran' ... ... Executing command 'which gfortran' ...No. ... Looking for file '/usr/local/bin/gfortran' ...Yes. ... Looking for folder '/usr/local/bin' ...Yes. ... Executing command 'which gfortran' ...No. ... Looking for file '/usr/local/bin/gfortran' ...Yes. ... Executing command 'gfortran -print-file-name=libgfortran.dylib' ...No. Did not find installed compiler 'gfortran'. Error using mex No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014a/maci64.
So that shows it still doesn't work.... Next attempt will be to find the gfortran archive for gfortran 4.3.x and try installing that after uninstalling 4.8.2
Attempt #2, gcc 4.3.X is pretty old wondering why MATLAB still uses it???
XXXX:~ XXXX$ fink list "gcc*"
Information about 9091 packages read in 1 seconds.
gcc4.2 4.2-0 [virtual package representing the gcc 4.2 compiler]
i gcc46 4.6.4-1001 GNU Compiler Collection Version 4.6
i gcc46-compiler 4.6.4-1001 Compiler Binaries for gcc46
i gcc46-shlibs 4.6.4-1001 Shared libraries for gcc4
gcc47 4.7.3-1001 GNU Compiler Collection Version 4.7
gcc47-compiler 4.7.3-1001 Compiler Binaries for gcc47
gcc47-shlibs 4.7.3-1001 Shared libraries for gcc4
gcc48 4.8.2-1001 GNU Compiler Collection Version 4.8
gcc48-compiler 4.8.2-1001 Compiler Binaries for gcc48
gcc48-shlibs 4.8.2-1001 Shared libraries for gcc4
gccxml 0.9-20130502.1 XML output extension to GCC
XXX:/ XXXX$ sudo ln -s /sw/lib/gcc4.6/bin/gfortran-fsf-4.6 /usr/local/bin/gfortran
XXXX:/ XXXX$ gfortran -print-file-name=libgfortran.dylib
/sw/lib/gcc4.6/lib/gcc/x86_64-apple-darwin11.4.2/4.6.4/../../../libgfortran.dylib
XXXXXXX:/ XXXX$ which gfortran
/sw/bin/gfortran
AFTER creating a symbolic link above still no joy!
EDU>> mex -v -largeArrayDims fulltosparse.F loadsparse.F
Verbose mode is on.
No MEX options file identified; looking for an implicit selection.
... Looking for compiler 'gfortran' ...
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...Yes.
... Looking for folder '/usr/local/bin' ...Yes.
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...Yes.
... Executing command 'gfortran -print-file-name=libgfortran.dylib' ...No.
Did not find installed compiler 'gfortran'.
Error using mex
No supported compiler or SDK was found. For options, visit
http://www.mathworks.com/support/compilers/R2014a/maci64.
See http://www.mathworks.com/matlabcentral/answers/116922-mex-cannot-find-gfortran-compiler-mac-os for the situation where the Terminal window can "find" gfortran, but MEX cannot.
@ Ken,
Thanks a million for your posts! After following the suggestions in the link directly above I was able to add the path to the startup.m file and finish following the example above with success.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!