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.