MATLAB: Does MATLAB not recognize the Xcode 9 installation when running “mex -setup”

compilerMATLABmexnosupportedxcode

Why does MATLAB report that I have "No supported compiler" when I execute "mex -setup", even though I have Xcode 9 installed on my machine and it is shown as a supported compiler on MathWorks.com?
 
>> mex -setup -v
Verbose mode is on.
... Looking for compiler 'Xcode with Clang' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Library/Developer/CommandLineTools').
... Looking for folder '/Library/Developer/CommandLineTools' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('9.0').
... Executing command '
agreed=9.0
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('9.0').
... Executing command 'xcrun -sdk macosx --show-sdk-path' ...No.
Did not find installed compiler 'Xcode with Clang'.
Error using mex
No supported compiler or SDK was found. For options, visit
<https://www.mathworks.com/support/compilers>.
 

Best Answer

"xcode-select -print-path" is reporting that the active developer directory is currently "/Library/Developer/CommandLineTools":
... Executing command 'xcode-select -print-path' ...Yes ('/Library/Developer/CommandLineTools').
This should be changed to the location of the Xcode.app in Applications, by using the "xcode-select" command from macOS Terminal:
 
sudo xcode-select -s /Applications/Xcode.app
Where "/Applications/XCode.app" is the location of your XCode 9 application. This command will require an administrator password.
Related Question