MATLAB Answers

Compiling mex files with XCode - Error using mex

26 views (last 30 days)
Jon B.
Jon B. on 26 Sep 2020 at 20:59
Commented: Jon B. on 26 Sep 2020 at 23:05
I am using Matlab R2020a in conjunction with Miranda & Fackler’s CompEcon library ( ) on a macOS Catalina operating system.
I am currently working on a Matlab script that, while it does deliver the desired results, takes an awfully long time to run through. As I was told that some functions in the CompEcon library have a C-version meant to optimize speed and memory efficiency, I figured that it would be worthwhile to make use of that.
In particular, CompEcon contains a function named mexall that is designed to compile all available mex files. So, in order to be able to run mexall, I downloaded and installed Xcode 12 as a compiler such that when I type
mex -setup C
Matlab says
MEX configured to use 'Xcode with Clang' for C language compilation.
Running the actual mexall function, however, generates a fair amount of warnings and finally an error to the effect that:
Error using mex
/Applications/CompEcon/CEtools/lusolve.c:35:13: error: implicitly declaring library function 'memcpy'
with type 'void *(void *, const void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
if (x!=b) memcpy(x,b,n*sizeof(double));
/Applications/CompEcon/CEtools/lusolve.c:35:13: note: include the header <string.h> or explicitly provide
a declaration for 'memcpy'
/Applications/CompEcon/CEtools/lusolve.c:154:7: warning: incompatible pointer types assigning to 'int *'
from 'mwIndex *' (aka 'unsigned long *') [-Wincompatible-pointer-types]
4 warnings and 1 error generated.
Error in mexall (line 26)
Nonetheless, it would seem that running mexall did generate quite a few mexmaci64-file for the m-files that have a corresponding C-version.
So, when I attempt to run my script despite the ocurrence of the error above, it takes a couple of seconds and then Matlab crashes with an error report that reads:
MATLAB crash file:/Users/username/matlab_crash_dump.4849-4:
Illegal instruction detected at Sat Sep 26 16:53:40 2020 -0400
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Unknown hardware
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : maci64
MATLAB Entitlement ID : 1495108
MATLAB Root : /Applications/
MATLAB Version : (R2020a) Update 4
OpenGL : hardware
Operating System : Mac OS Version 10.15.6 (Build 19G2021)
Process ID : 4849
Processor ID : x86 Family 6 Model 142 Stepping 9, GenuineIntel
Session Key : 6b43dc2e-7af0-4b10-9041-1f84c68a7111
Window System : Quartz
Fault Count: 4
Abnormal termination:
Illegal instruction
Register State (from fault):
RAX = a7066b851e5d0047 RBX = 00000000ffffffff
RCX = 00007fff6fb01d2e RDX = 0000000000001000
RSP = 0000700010cf6290 RBP = 0000700010cf6290
RSI = 00000001368b8000 RDI = 0000000000000103
R8 = 0000000000000000 R9 = 0000000000000000
R10 = 00000001368b8080 R11 = 0000000000000246
R12 = 0000600006811798 R13 = 00000000fce74800
R14 = 000060000665c000 R15 = 0000000110032058
RIP = 00007fff6fb96f3e RFL = 0000000000010202
CS = 000000000000002b FS = 0000000000000000 GS = 0000000000000000
Stack Trace (from fault):
This error message goes on and on for 34 lines.
I would very much appreciate any pointers as to how I could resolve this issue. Please let me know if you need any additional information.
Many thanks.


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Sep 2020 at 22:09
/Applications/CompEcon/CEtools/lusolve.c needs to have
#include <string.h>
added near the top.
/Applications/CompEcon/CEtools/lusolve.c needs to have the declaration for Ri changed from int * to mwIndex *
We can tell that the code was written in the days when 32 bit pointers were used. There might be additional similar problems lurking around.

  1 Comment

Jon B.
Jon B. on 26 Sep 2020 at 23:05
Thank you so much for your reply. Exactly the hint I needed. It would seem that there has been an effort to modify the mex files to be able to run in a 64 bit environment. Downloading the updated package did resolve all my problems.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by