how to enable mex -setup for newer compiler (Visual Studio 2022) on older MATLAB (R2018a) ?

54 次查看(过去 30 天)
I want to use a newer compiler with an older MATLAB.
Is there a mechanism by which we could configure R2018a's mex -setup to allow use of e.g. Visual Studio 2022 C/C++ ?
I understand that such a configuration might not be supported, and we'd be "on our own".
  1 个评论
Paolo Paniccia
Paolo Paniccia 2025-3-6
You can use a version of MATLAB compatible with the compiler to generate the appropriate configurations.
I will make the example considering
  • for the target compiler Visual Studio 2022 C/C++
  • for the new compatible version of MATLAB the R2023b
  • for the old not supporting version of MATLAB the R2018a
The first step, in MATLAB R2023b is to setup the compiler through the commands:
mex -setup
mex -setup C++
mex -setup -client MBUILD
mex -setup C++ -client MBUILD
the will generate in the folder %USERPROFILE\AppData\Roaming\MathWorks\MATLAB\R2023b the following files:
  • mex_C_win64.xml
  • mex_C++_win64.xml
  • MBUILD_C_win64.xml
  • MBUILD_C++_win64.xml
Those files must be copied in the folder %USERPROFILE\AppData\Roaming\MathWorks\MATLAB\R2018a, substituting the ones that are there present (in case you had already configured the mex compiler before).
Then you must substitute in each of them files the second last line
<MATLAB release="R2023b"/>
with the appropriate line
<MATLAB release="R2018a"/>
Now you can open MATLAB R2018a and run the same commands as above:
mex -setup
mex -setup C++
mex -setup -client MBUILD
mex -setup C++ -client MBUILD
MATLAB will prompt something in line with:
MEX configured to use 'Microsoft Visual C++ 2022 (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://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
(you can skip this last step, it is just to have confirmation that actually the mex is correctly configured to compile using the Visual Studio C++ 2022).
I hope that this helps.

请先登录,再进行评论。

回答(2 个)

Bruno Luong
Bruno Luong 2023-7-27
编辑:Bruno Luong 2023-7-27
Go to bin\win64\mexopts under matlabroot folder
Select one of the xml file (most recent supported MSVS C/C++)
Copy it there, rename and and mofidy to the config of 2022 MSVC.
You can compare two xml files to see what need to be changed.
We are not allowed to give you such file on most recent version, since it is copyrighted.
Good luck.
  1 个评论
Biyi Wang
Biyi Wang 2024-9-30
编辑:Biyi Wang 2024-9-30
Hi Bruno,
I met the similar problem, my matlab version is 2018b, and visual studio version is 2022.
I want matlab to detect the compiler integrated in the visual studio
(path:Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\Hostx64\x64\cl.exe)
I tried to copy and modify the associated xml file, however, I found for the newest matlab, it is only support the oneAPI.
I don't know how to modify the xml file, and I have not found something similar to solve this problem.
If you have the experience, could you please share your solution?
I really appreciate your help in advance.

请先登录,再进行评论。


Paolo Paniccia
Paolo Paniccia 2025-3-6
You can use a version of MATLAB compatible with the compiler to generate the appropriate configurations.
I will make the example considering
  • for the target compiler Visual Studio 2022 C/C++
  • for the new compatible version of MATLAB the R2023b
  • for the old not supporting version of MATLAB the R2018a
The first step, in MATLAB R2023b is to setup the compiler through the commands:
mex -setup
mex -setup C++
mex -setup -client MBUILD
mex -setup C++ -client MBUILD
the will generate in the folder %USERPROFILE\AppData\Roaming\MathWorks\MATLAB\R2023b the following files:
  • mex_C_win64.xml
  • mex_C++_win64.xml
  • MBUILD_C_win64.xml
  • MBUILD_C++_win64.xml
Those files must be copied in the folder %USERPROFILE\AppData\Roaming\MathWorks\MATLAB\R2018a, substituting the ones that are there present (in case you had already configured the mex compiler before).
Then you must substitute in each of them files the second last line
<MATLAB release="R2023b"/>
with the appropriate line
<MATLAB release="R2018a"/>
Now you can open MATLAB R2018a and run the same commands as above:
mex -setup
mex -setup C++
mex -setup -client MBUILD
mex -setup C++ -client MBUILD
MATLAB will prompt something in line with:
MEX configured to use 'Microsoft Visual C++ 2022 (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://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
(you can skip this last step, it is just to have confirmation that actually the mex is correctly configured to compile using the Visual Studio C++ 2022).
I hope that this helps.

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by