在 MacOS 系统中,使用 Matlab R2021a 编译时 C/C++ 代码时,配置编译器出现以下错误,也没有其他可用信息。
>> mex -setup
Error using mex
No supported compiler was found
根据官方文档(https://ww2.mathworks.cn/support/requirements/supported-compilers.html)查看支持的编译器,发现 R2021a 在 MacOS 系统中支持 Xcode 11.x 和 12.x。但是当前系统已安装了 Xcode 12.4,然而执行 mex -setup 仍然报错。后来进一步在 Matlab 中查看以下配置文件,才发现其中有一行提示如图,需要执行 xcode-select 切换路径。
>> edit ([matlabroot '/bin/maci64/mexopts/clang_maci64.xml'])
于是,首先执行 xcode-select -print-path 查看目前的路径,然后切换。
# Current path
(base) ➜ ~ xcode-select -print-path
/Library/D