1
votes

I have been stuck on this problem for several weeks and been looking around on Internet for solution but so far not so good...

So I have a program written by someone else and I try to compile it in Matlab to make it work. My computer is Red-hat enterprise Linux workstation (64 bits) with gcc 4.4.3 and Matlab 2011b installed. The gcc is compatible with my Matlab (http://www.mathworks.com/support/compilers/R2011b/glnxa64.html).

The compilation works fine (I mean, no error message occurs in Matlab command window). But after compilation, every time when I use a specific function from the compilation (it's call "mexLasso"), it will show up errors like this:

***Invalid MEX-file '/usr/local/matlab_R2011b/toolbox/spams-matlab/build/mexLasso.mexa64': /usr/local/matlab_R2011b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by /usr/local/matlab_R2011b/toolbox/spams-matlab/build/mexLasso.mexa64)

Error in test (line 24) alpha=mexLasso(X,D,param);*

So I type "strings /usr/lib/libstdc++.so.6 | grep GLIBC" in the terminal, and I found the "GLIBCXX_3.4.11" is actually in it.

I've been using Linux and gcc stuff for only several months...so there are still a lot of things I don't understand. It will be of great help if you can explain it in detail. Thanks!!

%% More detail: I got these programs on machine learning from http://spams-devel.gforge.inria.fr/downloads.html. The wierd thing is, after compilation, other functions in that package works fine (such as "mexTrainDL").

4
I checked the one provided in the ubuntuforums and followed his solution but it doesn't help :-( ["...removed both the symlink libstdc++.so.6 and its linked partner libstdc++.so.6* in /$MATLAB/sys/os/glnxa64 and replaced both of them with their counterparts of similar names in found in /usr/lib. (i.e. ln -s /usr/lib/libstdc++.so.6*)..."] - CSLearner
Using strings and grep is a little simplistic for looking at what a library defines, especially with C++ name mangling involved. Use nm and related tools as described here: stackoverflow.com/questions/34732/… - Andrew Janke
Sir, I use "readelf -Ws libstdc++.so.6" and found GLIBCXX_3.4.11, followed by a huge list of things like "2497: 00000000 0 OBJECT GLOBAL DEFAULT ABS GLIBCXX_3.4.13". Is that normal? - CSLearner

4 Answers

5
votes

The solution prompted by @whjiang works but have two limits:

  1. You may be required a sudo privilege to change the library symbol link.
  2. The change is global and can affect all users

So there is another.

As explained by this answer from MATLAB Central, the problem is caused by Matlab:

Matlab internally changes the LD_LIBRARY_PATH to prefer <MatlabPATH >/sys/os/<ARCH>

and the <MatlabPATH>/sys/os/libstdc++.so.6 is out of date.

The solution is set LD_PRELOAD when calling Matlab like this,

env LD_PRELOAD=/usr/lib/libstdc++.so.6  <MatlabPATH>/bin/matlab -desktop

The path of libstdc++.so.6 my be different from os to os. For example, on my LMDE2, the path is /usr/lib/x86_64-linux-gnu/libstdc++.so.6.

1
votes

Here is an solution:

sudo ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19 /usr/local/MATLAB/R2011b/bin/glnxa64/libstdc++.so.6

explanation and reference: http://fantasticzr.wordpress.com/2013/05/29/matlab-error-libstdc-so-version-glibcxx_3-4-15-not-found/

1
votes

A simple solution from this page ( http://ubuntuforums.org/showthread.php?t=808045 ) that worked for me. Go to the matlab directory where libstdc++.so.6 and libgcc_s.so.1 are stored. In my case, this was:

cd /usr/local/MATLAB/MATLAB_Production_Server/R2015a/sys/os/glnxa64

Then rename libstdc++.so.6 and libgcc_s.so.1:

sudo mv libstdc++.so.6 libstdc++.so.6.orig
sudo mv libgcc_s.so.1 libgcc_s.so.1.orig

That's it!