Borrar filtros
Borrar filtros

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

62 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 17 de Sept. de 2024 a las 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
  2 comentarios
Benjamin Thompson
Benjamin Thompson el 9 de Sept. de 2024 a las 19:56
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 el 11 de Sept. de 2024 a las 19:45
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by