1

I'm trying to call a function I wrote in C++ 11 from a mex script. The C++ code requires -std=c++11, and runs fine from the terminal. Here's g++ -v output: gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC) I have Matlab 2013a for Red Hat.

When I first tried calling mex filename.cpp from matlab console I got:

This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

So, I went into the /usr/local/MATLAB/R2013a/bin/mexopts.sh file that matlab uses to get compler options and added -std=c++11. Now I get:

cc1plus: error: unrecognized command line option "-std=c++11"

The full command gotten from mex -v filename.cpp is:

g++ -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -std=c++11  -DMX_COMPAT_32 -O -DNDEBUG  "mexMorph.cpp"

So, how can I get this to compile properly?

4

3 回答 3

2

尝试

墨西哥 CXXFLAGS="\$CXXFLAGS -std=c++11" simple_example.cpp

在不直接运行 Matlab 的情况下交替构建您的 mex 文件,例如使用 CMake,如下 github 存储库:mex-it

于 2015-01-10T19:42:44.927 回答
1

正如另一位响应者推测的那样,我的测试表明确实存在-ansi冲突。-std=c++11您可以编辑您的 mex 选项文件(例如~/.matlab/R2014a/mex_C++_glnxa64.xml在我的设置中)并删除-ansi. 另请注意,mex 接受-v标志,它会转储许多有用的调试信息。

于 2016-01-03T17:17:26.590 回答
0

这没有意义,但显然使用 -std=c++0x 会起作用。我认为 matlab 会事先进行一些检查,并且由于它不支持 4.8,因此即使编译器支持它也不接受它。任何人都可以支持我吗?

于 2015-01-06T19:59:50.870 回答