Category Archives: Machine Learning

Compiling MEX files using Mavericks OS X 10.9 and Matlab R2012a with Xcode 6.x

To compile MEX C and C++ files for Matlab R2012a using a Mac 10.9 Mavericks install with XCode 6.1, you will need to change the mexopts.sh settings found within the bin folder of the Matlab application.

cd /Applications/MATLAB_R2012a_Student.app/bin
ls
// make a copy of the original mexopts.sh file
cp mexopts.sh orig_mexopts.sh

Open the mexopts.sh file and search for SDK. On about line 167 you’ll find:

CC='gcc-4.2'
SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'
MACOSX_DEPLOYMENT_TARGET='10.5'
ARCHS='x86_64'
CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CFLAGS="$CFLAGS -fexceptions"
CLIBS="$MLIBS"
COPTIMFLAGS='-O2 -DNDEBUG'
CDEBUGFLAGS='-g'
#
CLIBS="$CLIBS -lstdc++"
# C++keyName: GNU C++
# C++keyManufacturer: GNU
# C++keyLanguage: C++
# C++keyVersion:
CXX=g++-4.2

I changed it to the following:

#CC='gcc-4.2'
#### Changed this line ####
CC='gcc'
#SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'
#### Changed this line ####
SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk'
MACOSX_DEPLOYMENT_TARGET='10.9'
ARCHS='x86_64'
CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET-Dchar16_t=uint16_t"
CFLAGS="$CFLAGS -fexceptions"
CLIBS="$MLIBS"
COPTIMFLAGS='-O2 -DNDEBUG'
CDEBUGFLAGS='-g'
#
CLIBS="$CLIBS -lstdc++"
# C++keyName: GNU C++
# C++keyManufacturer: GNU
# C++keyLanguage: C++
# C++keyVersion:
#CXX=g++-4.2
#### Changed this line ####
CXX=g++

Note that I specifically changed:

  • SDKROOT to the full path of the 10.9 SDK inside the XCode bundle
  • CC got changed from “gcc-4.2” to just “gcc”
  • CXX got changed from “g++4.2” to just “g++”
  • added -Dchar16_t=uint16_t to the end of CFLAGS to over come the fact the char16_t isn’t a native type.

From within the  /Applications/MATLAB_R2012a_Student.app/bin folder I ran ‘mex -setup’ and selected the revised version of mexopts.sh.

Seems to work. Should probably work with 2012a and 2012b but I don’t know.