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
MathWorks Support Team 2024 年 9 月 17 日
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
Benjamin Thompson 2024 年 9 月 9 日
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
MathWorks Supported Compilers Team 2024 年 9 月 11 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by