Invalid mex-file, libarmadillo, cannot open shared

2019-08-07 11:36发布

问题:

I know there are a lot of posts about the topic, this might be a duplicate, but I don't think so. My config is: Matlab R2014b, clang 3.4, Ubuntu 14.04, armadillo-4.600.4.

I have a local install (not system-wise, so including/linking manually) of Armadillo that works fine when outside of Matlab. I'm trying to run a Mex file using Armadillo from Matlab. It compiles fine using the command (truncated for short):

mex -compatibleArrayDims -outdir +mx -L/home/john/.local/arma/lib -larmadillo -I/home/john/.local/arma/include test_arma.cpp

Problem is when I try to run it I get this error:

Error using mx.test_arma
Invalid MEX-file '/path/to/+mx/test_arma.mexa64': libarmadillo.so.4: cannot open shared object file: No such file or directory

The environment variable LD_LIBRARY_PATH echoed from the shell that started Matlab contains /home/john/.local/arma/lib (where libarmadillo.so is), and I also manually added this path within Matlab using setenv('LD_LIBRARY_PATH',...). Is there something I'm missing?

回答1:

So I found out how to run it. Now it's segfaulting :/ And I'm fairly confident it's not the code itself, because I can compile and run the exact same code outside Matlab. I'll try to find out what's wrong, and if it's relevant, I'll post my adventures here later on.

For the running problem; it seems that Matlab uses the variable LD_RUN_PATH for loading shared libraries at runtime. Appending my path ... /.local/arma/lib to LD_RUN_PATH using setenv did the trick in my case. Cheers for your comments/answers!

Update: I finally solved this, the problem was due to an expected word-size mismatch (32/64 bits, ie int32_t vs. int64_t) between Matlab's BLAS/LAPACK libraries and Armadillo's calls. There are two solutions that I posted here.