mex -setup cannot find ifort on Mac
26 views (last 30 days)
Haomin Wang on 27 Dec 2021
I'm using matlab R2020b and I have Intel® Parallel Studio XE Composer Edition for Fortran macOS* 2019 installed.
When I run the command
mex -setup -v Fortran
I get the following
Verbose mode is on.
... Looking for compiler 'Intel Fortran Composer XE' ...
... Looking for environment variable 'IFORT_COMPILER20' ...No.
... Looking for environment variable 'IFORT_COMPILER19' ...No.
... Looking for environment variable 'IFORT_COMPILER18' ...No.
... Executing command 'which ifort' ...No.
Did not find installed compiler 'Intel Fortran Composer XE'.
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
If I run the command "which ifort" in my terminal, I get
I don't understand why matlab doesn't find my ifort compiler. Any help is appreciated!
Walter Roberson on 31 Dec 2021
It looks to me as if /usr/local/bin is not on your PATH during the mex command.
When a program is launched from an icon, it inherits only the basic system environment variables, and any setup that would normally be done in shells such as ~/.bash_profile is not executed -- because bash is not executed while launching a program from icon.
The system PATH environment variable is pretty sparse.
You might be able to modify a system plist file:
On the other hand, mex does, if I recall, invoke the shell to process the commands, so you might be able to setenv() at the MATLAB level.
With earlier MacOS versions you could have just linked /usr/bin/ifort to the appropriate location, but Big Sur and later seal some system directories and getting a permanent change into them is a nuisance.
Setting IFORT_COMPILER20 instead of setting PATH to be able to find ifort is probably a better idea (as suggested by @Anshika Chourasia ) -- but you might still need tricks to push it into the environment. It might be easier to put a setenv() call into your setup.m
More Answers (1)
Anshika Chourasia on 31 Dec 2021
The issue could be that MATLAB is not able to pick the FORTRAN compiler. Setting a environment variable should fix this issue. If you are using Intel FORTRAN 2020 set the environment variable ‘IFORT_COMPILER20’ to the original installation folder of the compiler.
Also, please note that the environment variable needs to be the actual installation folder and not a symbolic link for MATLAB R2020b.