Why does MATLAB R2024a crash when running a MEX file compiled with the Microsoft Visual Studio 2022 versions after 17.6.6?

38 次查看(过去 30 天)
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
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
  2 个评论
Benjamin Thompson
I am having a similar problem with MEX files compiled with v17.9.0 no longer working in MATLAB R2023B after I upgraded to v 17.10.4. Could this be the same thing? We are on R2023B Update 7. How can you determine if the MSVCP140 DLL is out of date for your MATLAB release? I could not find anything in the bug reports.
MathWorks Supported Compilers Team
Yes, this is most likely caused by the same issue. Most likely, any MSVCP140 DLL version after v17.9.0 will have this issue, regardless of the MATLAB version.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

尚未输入任何标签。

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by