Compiling Mex files in Mac 10.9

I'm trying to compile a mex file (in OS X 10.9) To be more specific, I'm trying to install the function SVMStruct (from http://www.robots.ox.ac.uk/~vedaldi/code/svm-struct-matlab.html#ssvm.download) but lack of mex command on my mac prevents from doing so. Here is the complete error message after typing
make MEX=/Applications/MATLAB_R2013a.app/bin/mex
/Applications/MATLAB_R2013a.app/bin/mex -largeArrayDims - CFLAGS='$CFLAGS -Wall' LDFLAGS='$LDFLAGS ' -outdir "build//" -c "svm_struct_api.c"
mex: - not a valid option.
Usage:
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
Use the -help option for more information, or consult the MATLAB External Interfaces Guide.
make: *** [build//svm_struct_api.o] Error 1
And this is the error message I receive when typing
make MEX=/Applications/MATLAB_R2013a.app/bin/mex ARCH=maci64
/Applications/MATLAB_R2013a.app/bin/mex -largeArrayDims -maci64 CFLAGS='$CFLAGS -m64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.4 -Wall' LDFLAGS='$LDFLAGS -mmacosx- version-min=10.4' -outdir "build/maci64/" -c "svm_struct_api.c"
xcrun: error: SDK "macosx10.7" cannot be located
clang: warning: no such sysroot directory: '/Developer/SDKs/MacOSX10.6.sdk'
svm_struct_api.c:20:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
mex: compile of ' "svm_struct_api.c"' failed.
make: *** [build/maci64/svm_struct_api.o] Error 1
The error talks about Mac OS X 10.6 and 10.7 but I'm using 10.9.

 Accepted Answer

Kamil - I observed the same error when running Make (from the terminal window, in the folder /Users/geoff/.../svm-struct-matlab-1.0) as make ARCH=maci64
...
Building with 'Xcode with Clang'.
clang: warning: no such sysroot directory: '/Developer/SDKs/MacOSX10.6.sdk'
/Users/geoff/.../svm-struct-matlab-1.0/svm_struct_api.c:20:10: fatal error: 'stdio.h' file not
found #include <stdio.h>
...
The Makefile has the following lines (of interest)
# Mac OS X Intel 32
ifeq ($(ARCH),maci)
SDKROOT ?= /Developer/SDKs/MacOSX10.6.sdk
This folder doesn't exist on my computer (OS X 10.8.5). Since MEX has been configured to use 'Xcode with Clang', the equivalent SDKs directory is
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
Within this directory, I have
MacOSX10.8.sdk
MacOSX10.9.sdk
So I changed the line in the Makefile from the
SDKROOT ?= /Developer/SDKs/MacOSX10.6.sdk
to
SDKROOT ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
and then re-ran make ARCH=maci64 and the svm_struct_learn.mexmaci64 file was built. (Running, in the Command Window of MATLAB, test_svm_struct_learn was successful).
I suggest you try updating the Makefile, in a similar manner as described above, with the appropriate MacOSX10.X.sdk.

5 Comments

That's a very good hint. However, after making those changes, I stumble upon the following problem after re-running:
make MEX=/Applications/MATLAB_R2013a.app/bin/mex ARCH=maci64
/Applications/MATLAB_R2013a.app/bin/mex -largeArrayDims -maci64 CFLAGS='$CFLAGS -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.4 -Wall' LDFLAGS='$LDFLAGS -mmacosx-version-min=10.4' -outdir "build/maci64/" -c "svm_struct_api.c"
xcodebuild: error: SDK "macosx10.7" cannot be located.
xcrun: error: unable to find utility "clang", not a developer tool or in PATH
mex: compile of ' "svm_struct_api.c"' failed.
make: *** [build/maci64/svm_struct_api.o] Error 1
I installed Xcode 6, which supposedly comes with all the command line tools such as clang.
Have you run
mex -setup
in the Command Window of MATLAB to setup Clang as the C/C++ compiler? Have you built MEX functions already, or is your first attempt at building one?
Kamil
Kamil on 13 Oct 2014
Edited: Kamil on 13 Oct 2014
What I did to fix this error was to edit the mexopts.sh file, that is I changed every instance of 10.7 to 10.8. Then, as indicated, I ran
mex -setup
And obtained
/Applications/MATLAB_R2013a.app/bin/mexopts.sh is being copied to
/Users/kamil/.matlab/R2013a/mexopts.sh
This seemed to work partially as now there is a different error:
/Applications/MATLAB_R2013a.app/bin/mex -largeArrayDims -maci64 CFLAGS='$CFLAGS -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.4 -Wall' LDFLAGS='$LDFLAGS -mmacosx-version-min=10.4' -outdir "build/maci64/" -c "svm_struct_api.c"
/Users/kamil/.matlab/R2013a/mexopts.sh: line 176: unexpected EOF while looking for matching `''
/Users/kamil/.matlab/R2013a/mexopts.sh: line 205: syntax error: unexpected end of file
/Users/kamil/.matlab/R2013a/mexopts.sh: line 176: unexpected EOF while looking for matching `''
/Users/kamil/.matlab/R2013a/mexopts.sh: line 205: syntax error: unexpected end of file
/Applications/MATLAB_R2013a.app/bin/mex: line 1343: -c: command not found
mex: compile of ' "svm_struct_api.c"' failed.
make: *** [build/maci64/svm_struct_api.o] Error 1
And this is the first time when I'm building a MEX function. And thanks a lot for your help.
Perhaps you deleted a single quote from around the '10.8' in the mexopts.sh file. Verify that the modifications you made to the file didn't accidentally remove a quote. i.e. should look like
MACOSX_DEPLOYMENT_TARGET='10.8'
You're right, one of the quotes was miswritten. Subsequently, another error appeared
/Applications/MATLAB_R2013a.app/bin/mex -largeArrayDims -maci64 CFLAGS='$CFLAGS -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.4 -Wall' LDFLAGS='$LDFLAGS -mmacosx-version-min=10.4' -outdir "build/maci64/" -c "svm_struct_api.c"
In file included from svm_struct_api.c:22:
In file included from ./svm_struct/svm_struct_common.h:28:
In file included from ./svm_struct/../svm_light/svm_common.h:22:
In file included from /Applications/MATLAB_R2013a.app/extern/include/mex.h:58:
In file included from /Applications/MATLAB_R2013a.app/extern/include/matrix.h:294:
/Applications/MATLAB_R2013a.app/extern/include/tmwtypes.h:819:9: error: unknown type name 'char16_t'
typedef char16_t CHAR16_T;
^
1 error generated.
mex: compile of ' "svm_struct_api.c"' failed.
make: *** [build/maci64/svm_struct_api.o] Error 1
which was fixed by modifying the file /Applications/MATLAB_R2013a.app/extern/include/tmwtypes.h:
typedef char16_t CHAR16_T;
into
typedef UINT16_T CHAR16_T;
Then finally the file "svm_struct_learn.mexmaci64" was built.

Sign in to comment.

More Answers (1)

psr
psr on 3 Dec 2016
This solution still works for me on Matlab R2015b on MacOSierra

Categories

Tags

Asked:

on 11 Oct 2014

Answered:

psr
on 3 Dec 2016

Community Treasure Hunt

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

Start Hunting!