Trace/breakpoint trap in MATLAB system call

Alec Jacobson

November 03, 2010

weblog/

I was trying to call ImageMagick's convert program from a matlab system call:
[status, result] = system(['/usr/local/bin/convert']);
But I get an error from matlab reading:
/opt/local/bin/convert: Trace/breakpoint trap
Upon inspecting the result I see that status is:
   133
and result says
Â…dyld: Library not loaded: /opt/local/lib/libtiff.3.dylib
  Referenced from: /opt/local/bin/convert
  Reason: Incompatible library version: convert requires version 13.0.0 or later, but libtiff.3.dylib provides version 11.0.0
If I run convert from my mac terminal everything runs just fine. After some investigation I found that this happens because MATLAB messes with the DYLD_LIBRARY_PATH variable. The fix is simple, just prepend your command like this:
[status, result] = system(['export DYLD_LIBRARY_PATH=""; ' '/opt/local/bin/convert']);
You don't even have to worry about setting DYLD_LIBRARY_PATH back, MATLAB is loading in its path for each system() call. What this does mean is that you have to prepend every system() command you make.