Mac下运行voc-dpm

因为搞voc-dpm,需要搭建matlab环境,折腾了很久才搞定。

我下载的是matlab2014b,下载后运行voc-dpm的demo会报如下的错误。

Error using mex No supported compiler or SDK was found. For options,
visit http://www.mathworks.com/support/compilers/R2014a/maci64.html.

参考Require,要求xcode 4.6+, gfortran 4.3.x, 都符合要求.mex -setup后仍然不行,显然matlab没有找到xcode的compiler。

翻各种资料终于找到,需要更新一个配置

1
>> edit ([matlabroot '/bin/maci64/mexopts/clang_maci64.xml'])

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<ISYSROOT>
<and>
<cmdReturns name="xcode-select -print-path"/>
<or>
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk" />
<cmdReturns name="find $$ -name MacOSX10.9.sdk" />
<cmdReturns name="find $$ -name MacOSX10.10.sdk" />
<cmdReturns name="find $$ -name MacOSX10.11.sdk" />
<cmdReturns name="find $$ -name MacOSX10.12.sdk" />
</or>
</and>
</ISYSROOT>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<SDKVER>
<and>
<and>
<cmdReturns name="xcode-select -print-path"/>
<or>
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk" />
<cmdReturns name="find $$ -name MacOSX10.9.sdk" />
<cmdReturns name="find $$ -name MacOSX10.10.sdk" />
<cmdReturns name="find $$ -name MacOSX10.11.sdk" />
<cmdReturns name="find $$ -name MacOSX10.12.sdk" />
</or>
</and>
<cmdReturns name="echo $$ | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'" />
</and>
</SDKVER>

处,分别增加10.12.sdk(我的系统是macOS Sierra + Xcode8.1)。

voc-dpm需要openmp的支持,但是mac的clang编译器并不支持,需要做如下的处理:

首先

1
2
brew install homebrew/boneyard/clang-omp
brew install homebrew/boneyard/libiomp

安装clang-omp, 然后ln -s /usr/local/lib/libiomp5.dylib /usr/local/lib/libgomp.dylib 创建符号链接, 此时系统存在一个支持omp的clang编译器和标准的clang编译器,继续修改clang_maci64
CC指令换成CC="$XCRUN_DIR/xcrun -sdk macosx$SDKVER clang-omp",然后include libs分别增加omp的引用位置

INCLUDE="-I&quot;$MATLABROOT/extern/include&quot; -I&quot;/usr/local/include/libiomp&quot; -I&quot;$MATLABROOT/simulink/include&quot;" LINKLIBS="-L&quot;$MATLABROOT/bin/maci64&quot; -L&quot;/usr/local/lib&quot; -lmx -lmex -lmat -lc++"

重启matlab mex -setup则正常.