无法运行Mex文件

时间:2015-04-17 20:42:27

标签: matlab mex

this link中,MATLAB代码带有用于SLIC算法实现的mex文件。

我通过编写mex slicmex.c在MATLAB中构建它。

然后我运行slicmex但收到此错误:

Matlab has encountered an internal error and needs to be closed. 

2 个答案:

答案 0 :(得分:0)

<强>更新

我最终修复了代码。在MEX文件源中,将行int* dims;更改为const mwSize* dims;。现在应该工作。

问题是代码不是64位友好的,并且对int的大小做了一些错误的假设。


我编译了他们用Visual Studio 2013提供的代码,从Matlab运行时生成的MEX文件出现致命错误。好像他们在某处划分为零。此时,您可以(1)联系原作者并让他们查看它或(2)自己修复代码。我在下面包含了错误消息和堆栈跟踪:

------------------------------------------------------------------------
       Integer divide by zero detected at Fri Apr 17 15:28:50 2015
------------------------------------------------------------------------

Configuration:
  Crash Decoding     : Disabled
  Default Encoding   : windows-1252
  MATLAB Architecture: win64
  MATLAB Root        : C:\Program Files\MATLAB\R2014a
  MATLAB Version     : 8.3.0.532 (R2014a)
  Operating System   : Microsoft Windows 7 Enterprise 
  Processor ID       : x86 Family 6 Model 58 Stepping 9, GenuineIntel
  Virtual Machine    : Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System      : Version 6.1 (Build 7601: Service Pack 1)

Fault Count: 1


Abnormal termination:
Integer divide by zero

Register State (from fault):
  RAX = 00000000000c0000  RBX = 0000000000000000
  RCX = 0000000000000000  RDX = 0000000000000000
  RSP = 00000000040260d0  RBP = 0000000004027260
  RSI = 0000000073de59e0  RDI = 0000000004026260

   R8 = 00000000097a81e0   R9 = 0000000000000201
  R10 = 00000000fe100000  R11 = 0000000004027260
  R12 = 000000000000127f  R13 = 00000000741ab430
  R14 = 0000000000000003  R15 = 0000000004027260

  RIP = 000007fef32c12fc  EFL = 00010206

   CS = 0033   FS = 0053   GS = 002b

Stack Trace (from fault):
[  0] 0x000007fef32c12fc C:\Users\***\Projects\Visual Studio\Workspaces\Personal\CppTest\x64\Debug\slicmex.mexw64+00004860 mexFunction+00000700
[  1] 0x00000000fc5ef711 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00063249 mexRunMexFile+00000129
[  2] 0x00000000fc5ee1e2 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00057826 inSwapMexfileReader+00000226
[  3] 0x00000000fc5ef294 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00062100 _constructor_lm_mexmaci64+00001620
[  4] 0x00000000045fbe4f C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00048719 Mfh_file::dispatch_fh+00000687
[  5] 0x00000000045fc77a C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00051066 Mfunction_handle::dispatch+00000810
[  6] 0x0000000004775e04 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00744964 MathWorks::MException::MExceptionEnvelope::GetID+00539764
[  7] 0x0000000004760782 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00657282 MathWorks::MException::MExceptionEnvelope::GetID+00452082
[  8] 0x0000000004753f6f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00606063 MathWorks::MException::MExceptionEnvelope::GetID+00400863
[  9] 0x000000000473cd43 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00511299 MathWorks::MException::MExceptionEnvelope::GetID+00306099
[ 10] 0x000000000474644f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00549967 MathWorks::MException::MExceptionEnvelope::GetID+00344767
[ 11] 0x0000000004749350 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00562000 MathWorks::MException::MExceptionEnvelope::GetID+00356800
[ 12] 0x000000000476446f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00672879 MathWorks::MException::MExceptionEnvelope::GetID+00467679
[ 13] 0x00000000047645b8 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00673208 MathWorks::MException::MExceptionEnvelope::GetID+00468008
[ 14] 0x0000000004754a2d C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00608813 MathWorks::MException::MExceptionEnvelope::GetID+00403613
[ 15] 0x000000000475192c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00596268 MathWorks::MException::MExceptionEnvelope::GetID+00391068
[ 16] 0x00000000047611c9 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00659913 MathWorks::MException::MExceptionEnvelope::GetID+00454713
[ 17] 0x00000000045fc00e C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00049166 Mfh_file::dispatch_fh+00001134
[ 18] 0x00000000045fc77a C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00051066 Mfunction_handle::dispatch+00000810
[ 19] 0x000000000474cdfe C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00577022 MathWorks::MException::MExceptionEnvelope::GetID+00371822
[ 20] 0x00000000047c68a7 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01075367 inEachVisibleName+00016119
[ 21] 0x000000000474ab1a C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00568090 MathWorks::MException::MExceptionEnvelope::GetID+00362890
[ 22] 0x000000000476446f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00672879 MathWorks::MException::MExceptionEnvelope::GetID+00467679
[ 23] 0x00000000047645b8 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00673208 MathWorks::MException::MExceptionEnvelope::GetID+00468008
[ 24] 0x0000000004754a2d C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00608813 MathWorks::MException::MExceptionEnvelope::GetID+00403613
[ 25] 0x000000000475192c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00596268 MathWorks::MException::MExceptionEnvelope::GetID+00391068
[ 26] 0x00000000047611c9 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00659913 MathWorks::MException::MExceptionEnvelope::GetID+00454713
[ 27] 0x00000000045fc00e C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00049166 Mfh_file::dispatch_fh+00001134
[ 28] 0x00000000045fc77a C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00051066 Mfunction_handle::dispatch+00000810
[ 29] 0x00000000047d4a0e C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01133070 inValidateLoadedObject+00003486
[ 30] 0x00000000047dbd95 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01162645 inResetInterpreter+00005029
[ 31] 0x00000000047e0a05 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182213 MathWorks::MException::MExceptionEnvelope::Copy+00010997
[ 32] 0x00000000047e09d2 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182162 MathWorks::MException::MExceptionEnvelope::Copy+00010946
[ 33] 0x00000000047e0997 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182103 MathWorks::MException::MExceptionEnvelope::Copy+00010887
[ 34] 0x0000000004bce89c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05302428 inMexPutVariable+00004204
[ 35] 0x0000000004bcebf6 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05303286 inMexPutVariable+00005062
[ 36] 0x0000000004bcf02e C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05304366 inMexPutVariable+00006142
[ 37] 0x0000000004bcf36c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05305196 inMexPutVariable+00006972
[ 38] 0x0000000004ae0161 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+04325729 inEvalCmdWithLocalReturn+00000065
[ 39] 0x000000000413becd C:\Program Files\MATLAB\R2014a\bin\win64\libmwbridge.dll+00048845 mnDebugPrompt+00000109
[ 40] 0x000000000413cfaf C:\Program Files\MATLAB\R2014a\bin\win64\libmwbridge.dll+00053167 mnParser+00000735
[ 41] 0x00000000fd0afae4   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00195300 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 42] 0x00000000fd093af0   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00080624 mcr::runtime::setInterpreterThreadToCurrent+00029488
[ 43] 0x00000000fd093b50   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00080720 mcr::runtime::setInterpreterThreadToCurrent+00029584
[ 44] 0x00000000fab6e026   C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00581670 UIW_IsUserMessage+00000086
[ 45] 0x00000000fab6e705   C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00583429 UIW_SetGLIMUserMsg+00000117
[ 46] 0x00000000fab6e789   C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00583561 UIW_SetGLIMUserMsg+00000249
[ 47] 0x00000000770a87fe                     C:\WINDOWS\system32\USER32.dll+00165886 GetMenuBarInfo+00000638
[ 48] 0x000000007708f5fb                     C:\WINDOWS\system32\USER32.dll+00062971 SystemParametersInfoW+00000235
[ 49] 0x0000000077094895                     C:\WINDOWS\system32\USER32.dll+00084117 IsProcessDPIAware+00000465
[ 50] 0x00000000772f04e5                      C:\WINDOWS\SYSTEM32\ntdll.dll+00328933 KiUserCallbackDispatcher+00000031
[ 51] 0x000000007709908a                     C:\WINDOWS\system32\USER32.dll+00102538 PeekMessageW+00000186
[ 52] 0x00000000770950fe                     C:\WINDOWS\system32\USER32.dll+00086270 GetKeyState+00000238
[ 53] 0x0000000077093a6f                     C:\WINDOWS\system32\USER32.dll+00080495 PeekMessageA+00000087
[ 54] 0x00000000fab1bd4b   C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00245067 UIW_SetCurrentDialog+00000731
[ 55] 0x00000000fab6fbe2   C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00588770 ws_FreeSystemFont+00000482
[ 56] 0x00000001000e2ed0 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+00995024 services::system_events::PpeDispatchHook::~PpeDispatchHook+00053488
[ 57] 0x00000001000e36a5 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+00997029 services::system_events::PpeDispatchHook::~PpeDispatchHook+00055493
[ 58] 0x00000001000e4330 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01000240 services::system_events::PpeDispatchHook::~PpeDispatchHook+00058704
[ 59] 0x00000001000ed4c6 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01037510 sysq::removeProcessPendingEventsHook+00011030
[ 60] 0x00000001000ed7ca C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01038282 svWS_ProcessPendingEvents+00000138
[ 61] 0x00000000fd094b6d   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00084845 mcr::runtime::setInterpreterThreadToCurrent+00033709
[ 62] 0x00000000fd094e3b   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00085563 mcr::runtime::setInterpreterThreadToCurrent+00034427
[ 63] 0x00000000fd088b75   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00035701 mcrInstantiationError::operator=+00003221
[ 64] 0x00000000fd08bea2   C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00048802 mcr_invoke_on_interpreter_thread+00001602
[ 65] 0x00000000fa7e6e5d C:\Program Files\MATLAB\R2014a\bin\win64\MVMLocal.dll+00159325 mvm_server::inproc::LocalFactory::createMVM+00040653
[ 66] 0x00000000051dafaa   C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00569258 mvm::detail::SessionImpl::privateSession+00001754
[ 67] 0x00000000051dd32a   C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00578346 mvm::detail::SessionImpl::privateSession+00010842
[ 68] 0x00000000051dce85   C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00577157 mvm::detail::SessionImpl::privateSession+00009653
[ 69] 0x0000000140004f79 C:\Program Files\MATLAB\R2014a\bin\win64\MATLAB.exe+00020345
[ 70] 0x0000000140006a07 C:\Program Files\MATLAB\R2014a\bin\win64\MATLAB.exe+00027143
[ 71] 0x00000000771959ed                   C:\WINDOWS\system32\kernel32.dll+00088557 BaseThreadInitThunk+00000013
[ 72] 0x00000000772cba01                      C:\WINDOWS\SYSTEM32\ntdll.dll+00178689 RtlUserThreadStart+00000033


This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/

A technical support engineer might contact you with further information.

Thank you for your help.

答案 1 :(得分:0)

我遇到了很多这些mex错误,这使得MATLAB崩溃了。

我想mex函数需要一些你没有给出的具体输入。

你知道,mex使用c / c ++指针访问输入数据,所以如果输入数据类型错误或输入数据错误,指针可能会超出范围。

最常见的情况是mex需要单个类型输入,但是你给出了一个double类型值,这是MATLAB中的默认数据类型。

我建议您检查一下mex源代码,找出所需的数据类型和输入数量。在C / C ++中,float *对应于MATLAB中的single,而double *对应于MATLAB中的double。

就是这样。希望你能解决它。