title: Mex files using Xcode 5.1 under OS X 10.9 with MATLAB 2012a
body: <p>I am trying to compile developer build for OpenCV (3.0.0), however I cannot configure my system to mex C files. I tried to follow suggestions from stackoverflow and currently I can mex c++ files, but not C ones. What I did was edit <code>mexopts.sh</code> so that correct <code>SDKROOT</code> was used, also I changed deployment targets to <code>10.9</code>.</p>
  
  <p>My mexopts.sh looks as follows:</p>
  
  <pre><code>    #PATCH: MacOSX10.8 // updated manually to 10.9
          CC='llvm-gcc'
          CXX='llvm-g++'
          SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'   
  
          #SDKROOT='/'
          MACOSX_DEPLOYMENT_TARGET='10.9'
          ARCHS='x86_64'
  
          # StorageVersion: 1.0
          # CkeyName: GNU C
          # CkeyManufacturer: GNU
          # CkeyLanguage: C
          # CkeyVersion:
          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: 
  
          # OLD
          #CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
          # NEW
          CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -std=c++11"
          CXXLIBS="$MLIBS -lstdc++"
          CXXOPTIMFLAGS='-O2 -DNDEBUG'
          CXXDEBUGFLAGS='-g'
  </code></pre>
  
  <p>Only after I added <code>-std=c++11</code> to the <code>CXXFLAGS</code> I was able to compile simple C++ code saved using <code>.cpp</code> extension. Here is the code for the file I want to compile</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;matrix.h&gt;
  #include &lt;mex.h&gt;
  
  void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
  {
    mexPrintf("Hello World!\n");
  }
  </code></pre>
  
  <p>I save it as <code>test.c</code> and compile. Here is the output i get</p>
  
  <pre><code>mex test.c
  </code></pre>
  
  <p>In file included from test.c:2:
  In file included from /Applications/MATLAB_R2012a.app/extern/include/matrix.h:295:
  /Applications/MATLAB_R2012a.app/extern/include/tmwtypes.h:819:9: error: unknown type
        name 'char16_t'
  typedef char16_t CHAR16_T;
          ^
  1 error generated.</p>
  
  <pre><code>mex: compile of ' "test.c"' failed.
  </code></pre>
  
  <p>Error using mex (line 206)
  Unable to complete successfully.</p>
  
  <p>The same error was used when the file was saved as <code>test.cpp</code> without <code>-std=c++11</code> in the <code>CXXFLAGS</code>. I am not experienced in C/C++ but is there some library or flag I need to add to fix the problem? Any suggestions, links would be helpful. </p>
  
  <p>Thank you. </p>