MATLAB: Using system() to Run LibreOffice / soffice on OSX

system

I'm running MATLAB 2013a on OSX and am attempting to convert a .xlsx file to a .pdf using MATLAB script. After determining that this couldn't be achieved using MATLAB alone, I downloaded LibreOffice to help me out. Running the following code in Mac Terminal works perfectly:
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf:writer_pdf_Export --outdir /Users/dwm8/Desktop/ /Users/dwm8/Desktop/box_copy.xlsx
This code saves the file box_copy.xlsx as a .pdf on my desktop. However, when I try running the same code in MATLAB using system():
system('/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf:writer_pdf_Export --outdir /Users/dwm8/Desktop/ /Users/dwm8/Desktop/box_copy.xlsx')
the .pdf does not get saved, and I get the error
dyld: Library not loaded: @loader_path/libcurl.4.dylib
Referenced from: /Applications/LibreOffice.app/Contents/Frameworks/libvcllo.dylib
Reason: Incompatible library version: libvcllo.dylib requires version 8.0.0 or later, but libcurl.4.dylib provides version 7.0.0
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf:writer_pdf_Export --outdir /Users/dwm8/Desktop/ /Users/dwm8/Desktop/box_copy.xlsx: Trace/breakpoint trap
Does anyone have a solution for this error? Thanks for the help!

Best Answer

You will need to set the environment variable DYLD_LIBRARY_PATH and possibly DYLD_FRAMEWORK_PATH as well, to point to different libraries. You can do that inside MATLAB by using setenv() before you system(), or you can do it on the command line that you system(). It also might work to unset DYLD_LIBRARY_PATH
system('unsetenv DYLD_LIBRARY_PATH; /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf:writer_pdf_Export --outdir /Users/dwm8/Desktop/ /Users/dwm8/Desktop/box_copy.xlsx')