But after you hack gfortran.xml to remove the references to that library, the problem remains that no matter what you do, mex forces -i8 to be added to the end of FFLAGS . That is a problem because -i8 is no longer used as a flag by gfortran.
After a bunch of poking around, I was able to work around these two problems.
Step 2 is to edit /Applications/MATLAB_R2017b.app/bin/maci64/mexopts/gfortran.xml (or as appropriate for your MATLAB version.) Replacement version is enclosed; unzip and put into that directory.
Note: I made several changes compared to the MATLAB provided version from the Question you linked to. I removed the several references to libgfortranbegin, and I added support for XCode SDK 10.12, and I coded the name of the fortran compiler as gfortrani8 in the FC assignment in the "vars" section. The changes I made to libgfortranbegin and SDK 10.12 should not give anyone any trouble, but the gfortrani8 that I introduced does not exist elsewhere.
Step 3 ... well if you installed from that source I gave, just assume the answer you need here is /usr/local/gfortran/bin and go on to Step 4.
Otherwise, go to a terminal window and in a shell (bourne shell family, not csh or zsh) execute
readlink $(which gfortran)
If it gives you back a non-empty answer then the result you need from this step is the directory of what it returns. For example if it returns /usr/local/gfortran/bin/gfortran then the answer you need is /usr/local/gfortran/bin
(If someone using Linux is trying to get some hints from this message, then readlink might not work for you: in that case
and take the directory of what is returned.)
What you need here is the name of the directory that the gfortran executables are really installed in, which is probably the same place that gcc is really installed in. This will likely not be /usr/local/bin even though there may be a /usr/local/bin/gfortran -- that probably points off to the real directory.
Step 4: download the file gfortrani8.zip that I enclose, and unzip it. It is a shell script. Now copy that shell script into the directory found through step 3. For example it might become /usr/local/gfortran/bin/gfortrani8 . Then, at the shell, chmod +x the script.
If you received this message when you mex'd:
Error using mex
gfortran: error: unrecognized command line option â-i8â; did you mean â-k8â?
then you need to be sure to install this gfortrani8 script.
If you receive this message:
Error using mex
/usr/local/gfortran/bin/gfortrani8: No such file or directory
then you did successfully install my gfortran.xml but you did not install my gfortrani8 (or did not get it into the right place.)
Step 5: go into MATLAB and
and do not worry if it says it did not already exist.
Step 6: in MATLAB,
If it tells you the compiler was found, then you should be able to proceed with compiling.
Step 7: In MATLAB you will probably need to,
setenv('DYLD_LIBRARY_PATH', [matlabroot(),'/bin/maci64:', matlabroot(), '/sys/os/maci64:', getenv('DYLD_LIBRARY_PATH')])
If your tests work, you might want to consider putting that into your startup.m file
Step 8: in at least some cases, when you compile, instead of just
you might need to
mex -client engine FileName.F
If you got the message
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)
when you mex'd, then this is probably the cure.
Step 9: run your code. If you did use the -client engine option then what was produced will be an external executable that you would execute with the system() or ! commands.
Step 10: curse when your program runs part way and then crashes...