Armadillo + Matlab Mex segfault
I fiddled with this the whole day, so I thought I might make everyone benefit from my experience, please see my answer below. I first had a problem with running a compiled Mex file within Matlab, because Matlab complained that it couldn't open the shared library libarmadillo . I solved this using the environment variables LD_LIBRARY_PATH and LD_RUN_PATH ( DYLD_LIBRARY_PATH and LYLD_RUN_PATH in osx). The problem remained however, that a simple test file would segfault at runtime even though the exact same code would compile and run fine outside Matlab (not Mex'd). The segfault seems to be