Mex can't find compiler after Xcode 7 update (R2015b)

I recently updated Xcode to version 7. I was able to use mex before, and now it thinks I don't have a valid compiler. I clearly have several valid C compilers:
$ which gcc
/usr/bin/gcc
$ which clang
/usr/bin/clang
Before I get waaay in the weeds with details, is there a way to point mex to a clearly installed compiler, or a mex config file to update?
Here is the verbose output:
$ mex -v Dependencies/anigaussm/anigauss_mex.c Dependencies/anigaussm/anigauss.c -output anigauss
Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require the use of
-largeArrayDims and remove the -compatibleArrayDims option.
For more information:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
No MEX options file identified; looking for an implicit selection.
... Looking for compiler 'Xcode with Clang' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...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 ('7.0').
... Executing command '
agreed=7.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 ('7.0').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' ...No.
... Executing command 'find /Applications/Xcode.app/Contents/Developer -name MacOSX10.9.sdk' ...No.
... Executing command 'find $$ -name MacOSX10.10.sdk' ...No.
Did not find installed compiler 'Xcode with Clang'.
No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2015b/maci64.html.c
Looks like the Xcode SDK version has incremented, despite OSX still being 10.10:
$ ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
MacOSX10.11.sdk
I tried creating a symlink there that points to MacOSX10.11.sdk, to no avail:
[...up to the fail point above...]
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.10').
Found installed compiler 'Xcode with Clang'.
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: /Applications/MATLAB_R2015b.app/bin/maci64/mexopts/clang_maci64.xml
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.10 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.10 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map" /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map" -L"/Applications/MATLAB_R2015b.app/bin/maci64" -lmx -lmex -lmat -lc++ -o /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.mexmaci64
CC : /usr/bin/xcrun -sdk macosx10.10 clang
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
INCLUDE : -I"/Applications/MATLAB_R2015b.app/extern/include" -I"/Applications/MATLAB_R2015b.app/simulink/include"
COPTIMFLAGS : -O2 -DNDEBUG
CDEBUGFLAGS : -g
LD : /usr/bin/xcrun -sdk macosx10.10 clang
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.10 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map"
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map"
LINKLIBS : -L"/Applications/MATLAB_R2015b.app/bin/maci64" -lmx -lmex -lmat -lc++
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
SETENV : CC="/usr/bin/xcrun -sdk macosx10.10 clang"
CXX="/usr/bin/xcrun -sdk macosx10.10 clang"
CFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -DMX_COMPAT_32 -DMATLAB_MEX_FILE"
CXXFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -DMX_COMPAT_32 -DMATLAB_MEX_FILE"
COPTIMFLAGS="-O2 -DNDEBUG"
CXXOPTIMFLAGS="-O2 -DNDEBUG"
CDEBUGFLAGS="-g"
CXXDEBUGFLAGS="-g"
LD="/usr/bin/xcrun -sdk macosx10.10 clang"
LDXX="/usr/bin/xcrun -sdk macosx10.10 clang"
LDFLAGS="-Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.10 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map" -L"/Applications/MATLAB_R2015b.app/bin/maci64" -lmx -lmex -lmat -lc++ -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015b.app/extern/lib/maci64/mexFunction.map""
LDDEBUGFLAGS="-g"
DEVELOPER_DIR_CHECK :
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /usr/bin
XCODE_AGREED_VERSION : 7.0
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
SDKVER : 10.10
MATLABROOT : /Applications/MATLAB_R2015b.app
ARCH : maci64
SRC : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss_mex.c;/Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss.c
OBJ : /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o;/var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.o
OBJS : /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.o
SRCROOT : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss_mex
DEF : /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.def
EXP : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.exp
LIB : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.lib
EXE : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.mexmaci64
ILK : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.ilk
MANIFEST : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss.mexmaci64.manifest
TEMPNAME : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/anigauss
EXEDIR : /Users/m29474/Desktop/code/selective_search_ijcv_with_python/
EXENAME : anigauss
OPTIM : -O2 -DNDEBUG
LINKOPTIM : -O
CMDLINE100_0 : /usr/bin/xcrun -sdk macosx10.10 clang -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015b.app/extern/include" -I"/Applications/MATLAB_R2015b.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O2 -DNDEBUG /Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss_mex.c -o /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o
CMDLINE100_1 : /usr/bin/xcrun -sdk macosx10.10 clang -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015b.app/extern/include" -I"/Applications/MATLAB_R2015b.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O2 -DNDEBUG /Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss.c -o /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.o
CMDLINE300_0 : rm -f /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o
CMDLINE300_1 : rm -f /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss.o
-------------------------------------------------------------------
Building with 'Xcode with Clang'.
/usr/bin/xcrun -sdk macosx10.10 clang -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015b.app/extern/include" -I"/Applications/MATLAB_R2015b.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.10 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O2 -DNDEBUG /Users/m29474/Desktop/code/selective_search_ijcv_with_python/Dependencies/anigaussm/anigauss_mex.c -o /var/folders/bt/bct7b52x0sb25z0pd5ky23xsg9dl8x/T//mex_32352732774360_62273/anigauss_mex.o
xcodebuild: error: SDK "macosx10.10" cannot be located.
xcrun: error: unable to find utility "clang", not a developer tool or in PATH
Help!
-Austin

 Accepted Answer

EDIT MathWorks has produced a patch for this issue. If at all possible, use the procedure outlined at http://www.mathworks.com/matlabcentral/answers/246507-why-can-t-mex-find-a-supported-compiler-in-matlab-r2015b-after-i-upgraded-to-xcode-7
Original Answer
This is an advanced maneuver, but get rid of that symlink and try doctoring this file:
>> edit ([matlabroot '/bin/maci64/mexopts/clang_maci64.xml'])
Toward the bottom, you will see a line that look like this, referencing "10.10":
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk" />
Copy and paste this line (immediately after the first) and change the second one to "10.11", like this:
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />
Do this against for another instance in this file -- both must be modified.
This should allow you to link against the OS X 10.11 SDK, but please be aware that this is configuration that has not been validated by MathWorks.

12 Comments

Thank you! I actually tried this hours ago but apparently forgot to edit both lines.
When I try this in R2014a the clang_maci64.xml file is certainly there, but it is apparently not being used. I can edit it, corrupt it, remove it completely, and MATLAB goes ahead creates its own commands.
Check your 'prefdir' for mex*.xml files. These get created when you run 'mex -setup' (which, as-of a few releases ago, is now optional and almost always not necessary) and will be used instead of the XML file I mention here.
Thanks, [prefdir 'mex_c_maci64.xml'] did the trick!
FWIW - many people will want to make the same edits here
edit ([matlabroot '/bin/maci64/mexopts/clang++_maci64.xml'])
Hi, What would be the directory if only the command line tools are installed without the full Xcode.app ? I have no .sdk folder.
xcode-select -print-path
/Library/Developer/CommandLineTools
Below full output of my mex -setup -v:
>> 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' ...Yes ('4.6.3').
... Executing command '
agreed=4.6.3
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 ('4.6.3').
... Executing command 'xcode-select -print-path' ...Yes ('/Library/Developer/CommandLineTools').
... Looking for folder '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...No.
... Looking for folder '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' ...No.
... Looking for folder '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...No.
... Executing command 'find /Library/Developer/CommandLineTools -name MacOSX10.9.sdk' ...No.
... Executing command 'find $$ -name MacOSX10.10.sdk' ...No.
... Executing command 'find $$ -name MacOSX10.11.sdk' ...No.
Did not find installed compiler 'Xcode with Clang'.
Error using mex
No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014b/maci64.html.
It's 2 days I've been trying to fix this issue. Thanks you so much!!!
It works for MATLAB_R2014a as well. Thank you!
Just got it working with R2015b, running on OS X El Capitan Version 10.11.6, XCode version 7.3.1 installed in default /Applications, and command line tools installed.
Modify XML file directly using:
- vi /Applications/MATLAB_R2015b.app/bin/maci64/mexopts/clang_maci64.xml
- changed affected lines (120-123 & 132-135) to MacOSX10.10.sdk and MaxOSX10.11.sdk
- restart matlab
- mex -setup (in Matlab command line window)
- done
I was facing similar problem after upgrading to Xcode 8.0. Tried this solution which worked. But one need to add following line at the places Ken suggested:
Hey! I have been trying to get this to work with Xcode 8.0 (after macOS Sierra upgrade). Just changing this line didn't work for me. Did you change anything besides this as well?

Sign in to comment.

More Answers (4)

if you use macOS 10.12.5 Sierra with Xcode 8.3.3,this file will work for Matlab 2016a:
Hi Ken,
I am using 2014b, OSX 10.10.5 and installed Xcode 7. just tried to simply run 'mex fengdemo.F'. The fortran file is matlab example file. I made the change as you described above. 'mex -setup' seems ok;
I got this:
Building with 'gfortran'. f951: Warning: Nonexistent include directory '/Applications/MATLAB_R2014b.app/simulink/include' [-Wmissing-include-dirs]
Error using mex clang: error: no such file or directory: '1/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk'
Error in chentry (line 4) mex fengdemo.F;
Can you help?!

5 Comments

by the way I run 'xcode-select -p' in terminal
get this
/Volumes/Xcode 1/Xcode.app/Contents/Developer'
It appears to me that you have an XCode .dmg mounted instead of having installed in /Applications
The missing include directory might not be important at the moment.
Xcode.app is in Applications fold of my laptop;but why it shows '/Volumes/Xcode 1/Xcode.app/Contents/Developer' by 'xcode-select -p' command. By the way, I am using company computer, which might be set by our IT support, I guess.
god! when i run 'sudo xcode-select -switch /Applications/Xcode.app/ ' It needs password.
Is there any way to modify matlab files instead of asking IT guys?
No, you will need the sudo unless you install MATLAB in your own directory instead of available across the machine... but you would need authorization from your IT people for that.

Sign in to comment.

Hi all,
mine is like as follows but still can't use mex files.
<cmdReturns name="xcode-select -print-path"/>
<or>
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />
<cmdReturns name="find $$ -name MacOSX10.9.sdk" />
<cmdReturns name="find $$ -name MacOSX10.10.sdk" />
<cmdReturns name="find $$ -name MacOSX10.11.sdk" />
</or>
Any suggestions?
Thanks

4 Comments

Current versions of XCode are MacOSX10.12 . Also you need to do the same thing further down: you need to do it for ISYSROOT and for SDKVER
I have attached my versions. In R2016b these would go in /Applications/MATLAB_R2016b.app/bin/maci64/mexopts
I had to zip them because .xml attachments are not allowed. You will need to unzip and put the contents into the above directory.
This file has been tested for R2016b and R2017a, on El Capitan (XCode 8.0, XCode 8.1, Xcode 8.2), and on Sierra (XCode 8.3). It is, however, not suitable for R2016a; I will upload that version in a moment.
R2016a has some aspects in different locations than R2016b or R2017a. Although the editing techniques and the files to change are the same for all three versions, the final files for R2016a are different than for R2016b / R2017a. I have attached the modified R2016a versions here. Unzip and put the two files into /Applications/MATLAB_R2016a.app/bin/maci64/mexopts
Hi, it says
Error using mex /Applications/MATLAB_R2016a.app/bin/maci64/mexopts/clang++_maci64 2.xml is not a valid XML file.
I might have accidentally uploaded aliases instead of the actual files. For R2016a try with the enclosed:

Sign in to comment.

Lin Yuan
Lin Yuan on 9 Feb 2017
Edited: Lin Yuan on 9 Feb 2017
Another answer, but I think it's basically the same as the previous answers.
First, you need to locate to the c++ compiler in your Matlab. Mine is /Applications/MATLAB_R2016a.app/bin/maci64/mexopts
And open the clang++_maci64.xml file with any editor, check/add the following line of codes(as the attached image highlighted)
I think, if your Matlab version are older than the system version being released(e.g OS 10.12 Sierra), it shouldn't add them in the file, so just add them manually could probably solve this kind of problem.

3 Comments

Hi
having the sane errors of invalid mex file Iread most of the comments regarding that issue withe no success.
if possible, ill need instructions step by step
Mac OS high Sierra & Score 9.2
Invalid MEX-file '/Users/ericelharar/Documents/MATLAB/Eric_Pedro/BM3D/bm3d_thr.mexmaci64':
dlopen(/Users/ericelharar/Documents/MATLAB/Eric_Pedro/BM3D/bm3d_thr.mexmaci64, 6): Library not loaded: @loader_path/libmat.dylib
Referenced from: /Users/ericelharar/Documents/MATLAB/Eric_Pedro/BM3D/bm3d_thr.mexmaci64
Reason: image not found.
Eric
Hi Eric,
Do you find the reasons of the error? I have the same issue.
In Sierra and later, Apple started enforcing a System Integrity feature.
The documented effect is that for some Apple provided apps that the app would ignore LD_LIBRARY_PATH and DYLD_LIBRARY_PATH and only link libraries in some places such /usr/lib.
The actual effect appears to be that it is doing that security for all or most applications in /Applications including matlab since it is installed there.
The work around is to copy the appropriate libraries into /usr/lib or to at least have a symbolic link there pointing to the actual location.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!