win10系统使用vs community作为matlabb编译器

时间:2024-04-04 13:40:36

第二次补充:装了matlab2017a的同志碰到这个问题也可以试一下,官方也给了相应的附件 attachment_1487958_17a_win64_2017-05-10.zip


第一次补充:如果下面的步骤没有生效,大家可以检查一下vs2017是否有安装“C++桌面开发”功能,详情见 vs2017补充安装


小伙伴们可能会发现,同时装了matlab2016b和vs2017 community之后,想要用mex -setup来使用matlab编译C/C++文件,发现在命令行输入mex -setup以后提示找不到编译器,这就奇了怪了,明明装了VS,为何找不到编译器?难道是vs2017不支持matlab2016b么?

带着好奇心我去看了一下matlab官方的文档中关于版本支持的编译器,发现vs2017是可以支持的,链接请看:matlab2016b支持的编译器列表 可以看到Microsoft Visual C++ 2017 Family 12 。注意看一下这个12是右上角的标注,我们往文档下面拉可以看到family的意思是:12. Community, Professional, and Enterprise editions are supported 这里所说的意思很明显了,community肯定是支持的。

那么为什么会出现上面的问题呢?别着急,我们再看一下,那个支持列表里面的Microsoft Visual C++ 2017 Family后面还有一个小括号,里面的内容是:Patch required 是的,不用怀疑,点进去就对了。

点进去我们会发现,原来我们还需要安装一些东西才可以,按照里面第一条回答,选择自己所需要的功能,点击相应的链接。这里我以自己需要的MEX-file compilation 为例讲解一下解决过程。这里点击链接可能会提示需要登录mathworks账号才能查看,大家按照步骤注册或者登录就行。实在不想登录的也可以接着看如下的过程。

先从上往下读一下,读不懂也没关系,重点看到Installation instructions这里,我用中文稍微解释一下:

  1. Log in to an account with appropriate permissions to overwrite files in your MATLAB installation.(就是打开你安装好的matlab)
  2. Locate your MATLAB installation by typing matlabroot at the MATLAB command prompt. This folder is referred to as < MATLAB > in subsequent steps.(在命令窗口输入matlabroot来获取matlab安装的路径,这个路径我们下面统一称为< MATLAB >)
  3. Exit MATLAB. (退出matlab)
  4. Download the attached .zip file associated with this Bug Report and store the file in the folder. You may need administrative privileges to save the .zip file in the folder. To do this, open this Bug Report in a browser started in administrator mode, then from the browser save the .zip file in the < MATLAB > folder.(下载附件的zip文件,attachment_1487958_16b_win64_2017-05-10.zip 先不用解压,并将其放到刚刚所说的< MATLAB >路径下。由于我们一般matlab是安装到了C盘里面,所以复制文件可能需要提供管理员权限,照着勾选管理员权限就行。)
  5. For each file that appears in the .zip file, find the corresponding file in your existing < MATLAB > folder and make a backup of it. (这里提示说查看压缩文件夹下与< MATLAB >路径下同名的文件,需要先备份一下,以免覆盖文件时导致文件丢失。)
  6. Extract the files from the .zip file into the < MATLAB > folder. You may be prompted to provide Administrator privileges when extracting the .zip file.(将压缩包解压缩到< MATLAB >文件夹,注意这里解压缩的选项,是解压缩到当前文件夹,不是解压到一个与压缩包同名的文件夹,这里的目的就是把一些附加的文件添加到原来的文件夹下,所以其实我发现并没有覆盖原来的文件夹,而是原来文件夹下面多了文件)
  7. Delete the .zip file in the < MATLAB >folder. (删除压缩包文件)
    随后我们再次打开matlab,输入mex -setup就可以看到想要的编译器了。
    win10系统使用vs2017 community作为matlab2016b编译器
    上面是楼主之前不知道这个解决办法,入了坑,装了别的编译器,这个后面再写博客讲在没有装vs的情况下怎么安装别的编译器。如上,点击microsoft visual C++ 2017就行。