Mex file compiles in Visual Studio but crashes MATLAB, getting error in debug.
조회 수: 1 (최근 30일)
이전 댓글 표시
HI Matlab central community. I tried to ask this question in StackOverflow but I could not resolve it. I compile a mex file in VIsual Studio 2013, which is very basic:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Hello! :)\n");
return;
}
This compiles as a mexw64 succesfully. I then open up MATLAB v2016a, and try to run mcx() with no input parameters and mcx(cfg) where cfg has 1,2 or 3 parameters. Each different scenario cases MATLAB to crash, end prematurely. I attach visual studio to MATLAB, and I get the error:
'MATLAB.exe' (Win32): Loaded 'C:\Users\tub08918\Google Drive\Patil Lab\AlexsFolderPleaseVisitMe\RamanMonteCarlo\mcx-2017.3-src\mcx\vsproj\mcx\x64\Debug\mcx.mexw64'. Symbols loaded.
First-chance exception at 0x00000000000260A8 in MATLAB.exe: 0xC0000005: Access violation executing location 0x00000000000260A8.
> throw_segv_longjmp_seh_filter()
throw_segv_longjmp_seh_filter(): invoking THROW_SEGV_LONGJMP SEH filter
> throwSegvLongjmpFilter()
MATLAB.exe has triggered a breakpoint.
Now the aim is to compile a file with CUDA capabilities, bu I can't even figure out what is causing this very simple ne-line code to fail. My props file comes from https://github.com/chappjc/MATLAB/tree/master/propertySheets. My build is x64 and I made sure to compile as x64. I tried using a new project that didnt help, so I am out of ideas why this simple code would be compiling as a mex file but failing when called from MATLAB. Interstingly, if I leave mexFunction blank, then MATLAB does not crash. IF I have some easy operations, like 2+2, MATLAB does not failk. It seems to happen when I call any function built into c++ or from mex.h
채택된 답변
Philip Borghesani
2017년 4월 5일
편집: Philip Borghesani
2017년 4월 5일
First suggestion build with the mex command instead of directly with visual studio. Make sure that works. Then check your compile options against those displayed with mex -v . If this was x32 then I would blame the calling convention, MATLAB requires cdecl default.
Some first chance access violations are expected due to the use of Java. If the mex file works without a debugger attached and continue works (might require multiple and frequent continues... disable first chance access violation checking) then there are no problems with the code.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!