How to solve segmentation violation error when I call a C-MEX function which is compiled correctly?

1 view (last 30 days)
Hi;
I have compiled a C-mex file in matlab successfully. But, when I try to call it in a matlab program, "Segmentation violation" error appears and Matlab is forced to close. The error which I get is:
------------------------------------------------------------------------
Segmentation violation detected at Wed Apr 27 16:51:04 2015
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Crash Mode : continue (default)
Current Graphics Driver: Unknown hardware
Current Visual : 0x23 (class 4, depth 24)
Default Encoding : UTF-8
GNU C Library : 2.19 stable
Host Name : iampc25
MATLAB Architecture : glnxa64
MATLAB Root : /opt/MATLAB/R2015a
MATLAB Version : 8.5.0.197613 (R2015a)
OpenGL : hardware
Operating System : Linux 3.19.0-32-generic #37~14.04.1-Ubuntu SMP x86_64
Processor ID : x86 Family 6 Model 60 Stepping 3, GenuineIntel
Virtual Machine : Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11701000), display :0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00007f94bdadd7f0 RBX = 0000000000000001
RCX = 00007f95d6d0c320 RDX = 00007f95e3ede870
RSP = 00007f95e3ede520 RBP = 00007f95e3ede8b0
RSI = 00007f95d6d0c358 RDI = 0000000000000008
R8 = 000bf5f8000000c0 R9 = 0000000000000008
R10 = 0003fca800000040 R11 = 0003fca800000040
R12 = 000bf5f8000000c0 R13 = 00007f95e3ede870
R14 = 00007f95d6d0c320 R15 = 00007f95e3ede870
RIP = 00007f94bdaddeda EFL = 0000000000010202
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007f94bdaddeda /opt/MATLAB/R2015a/bin/glnxa64/mkl.so+15728346
[ 1] 0x0000000000000000 <unknown-module>+00000000
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.
any help is appreciated !!
  4 Comments

Sign in to comment.

Answers (1)

Alessandro Masullo
Alessandro Masullo on 28 Apr 2016
I suggest you to run a debugger on your C file. I've never done it on GNU/Linux, but it should be possible in the same way as on Windows.
Simply open your debugger, attach it to the process of Matlab, compile your mex file with "-g", set a debug point in your mex routine, run it from matlab and execute your C file line by line. When Matlab crashes, you can see exactly where your C file is generating the error.
Hope it helps.

Community Treasure Hunt

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

Start Hunting!

Translated by