然后打开Matlab依次输入:
>>cd( prefdir );
>>cd( fullfile( matlabroot, 'bin', 'maci64', 'mexopts' ) );
>>mkdir mexoptsContentsOLD;
>>movefile *.xml mexoptsContentsOLD/
>>movefile( '~/Downloads/xcode7_mexopts/*.xml', '.' );
>>mex -setup
这样做后提示还是找不到SDK,查了https://cn.mathworks.com/matlabcentral/answers/303369-mex-cannot-find-a-supported-compiler-in-matlab-r2015b-after-i-upgraded-to-xcode-8-0后找到了原因 ,处理方法如下:
转到文件夹/Applications/MATLAB_R2015b.app/bin/maci64/mexopts并在Matlab中直接打开编辑编辑文件clang ++ _ maci64.xml和clang_maci64.xml。在这两个文件中,搜索包含字符串MacOSX10.10.sdk或MacOSX10.11.sdk的行。复制该行并将其更改为MacOSX10.12.sdk。您将需要在两个文件中的每一个文件中更改4行总数,一行提及dirExists,然后是一行,再次提及cmdReturns,然后再同一个。
这样做后使用mex -setup即出现如下提示:
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
表明可以用C编程
然后使用 mex hello.c(类似c文件)即可编译得到mexmaci64格式(类似windows的dll)的文件,再通过Matlab运行相关函数时即可自动使用该文件进行编程,不会出现找不到原函数的情况。
