Jan 242015
 

This caused me a bit of grief but the solution is somewhat anticlimactic for how long it took me! When I tried to mex compile some C++11 code with the “out of the box” mex compiler I ran into the following errors of the following type:

  1. warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  2. warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  3. no type named ‘shared_ptr’ in namespace ‘std’

And all sorts of weird stuff even though it compiled fine with clang++ on the command line. Essentially it came down to make the following adjustments to the mexopts file:

/Applications/MATLAB_R2014a.app/bin/maci64/mexopts/clang++_maci64.xml:

by adding adding -std=c++11 -stdlib=libc++ to CXXFLAGS:

And then forcing mex to use that file with -f and specifically including the path of the mex.h header file with -I:

Let’s see it in action with Lambda’s, introduced in C++11. Suppose the following is contained in lambda_hello_world.cpp.

Then inside MATLAB we execute the following:

Some references:

  1. http://www.cprogramming.com/c++11/c++11-lambda-closures.html
  2. http://stackoverflow.com/questions/16939734/matlab-mex-clang-c11-thread-undefined-symbols-error
  3. http://www.shawnlankton.com/2008/03/getting-started-with-mex-a-short-tutorial/