Why does MATLAB R2024a crash when running a MEX file compiled with the Microsoft Visual Studio 2022 versions after 17.6.6?
5 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2024-8-23,0:00
回答: MathWorks Support Team
2024-8-23,11:40
My MEX file was working with Visual Studio 2022 version 17.6.6 and earlier versions, but, after compiling my MEX function with the latest version of Visual Studio 2022 (for example, Version 17.10.2), it crashes during execution. When I look at the crash report, i see "MSVCP140.dll" or "VCRUNTIME140_1d.dll" at or near the top of the Stack Trace.
How can I resolve this crash?
采纳的回答
MathWorks Support Team
2024-8-23,0:00
The newest Microsoft Visual Studio compiler has some changes in the MVSC runtime library that are incompatible with the version shipped by MATLAB. This version incompatibility can cause a crash during execution.
There are 3 possible workarounds to resolve this issue:
1) Revert to Visual Studio 2022 version 17.6.6, or earlier.
2) Define the "_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR" macro in the source code itself (see code, below) and recompile the MEX file.You will need to test your code to make sure it is not affected by defining this macro. This option may be preferable if you will be sharing your MEX file.
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
3) Replace the "msvcp140.dll" that is shipped with MATLAB with the one from Visual Studio. To do so, follow these steps.
- Locate and rename the MATLAB "msvcp140.dll". For example, rename "matlabroot\bin\win64\msvcp140.dll" as "matlabroot
\bin\win64\msvcp140_original.dll", where "matlabroot" is the output this command executed in MATLAB.
>> matlabroot
- Locate and copy the new "msvcp140.dll" file into the "matlabroot\bin\win64" folder. A typical location for the "msvcp140.dll" file is in the "C:\Windows\System32" folder. Restart MATLAB and try to execute your workflow
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!