1

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").

CSLearner
  • 11
  • 1
  • 1
  • 5
  • http://ubuntuforums.org/showthread.php?t=1809300 Same problem. Is it yours ? – DumbCoder Mar 21 '14 at 16:41
  • http://stackoverflow.com/questions/6284679/executing-binary-glibcxx-3-4-11-not-found – DumbCoder Mar 21 '14 at 16:42
  • 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 Mar 21 '14 at 17:05
  • 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: http://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file – Andrew Janke Mar 21 '14 at 18:09
  • 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 Mar 21 '14 at 19:05

4 Answers4

5

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.

Yantao Xie
  • 12,300
  • 15
  • 49
  • 79
  • thank you!! that really made my day (or night rather) :) – Nikole Oct 14 '16 at 00:00
  • Any way to make this fix permanent? Rather than running each time this: env LD_PRELOAD=/usr/lib/libstdc++.so.6 /bin/matlab ??? – seralouk Jan 29 '19 at 12:59
  • @seralouk I think it's possible if you write a script to consider these problems such as the version of Matlab and the type and version of OS, etc.. So I don't think it's worth to do. – Yantao Xie Jan 30 '19 at 06:25
2

This is answered in the libstdc++ FAQ: http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • Hi, thank you for the thought! I actually found out there are two linux accounts in my computer, and I need to compile it using the root account in order to use it in the user's account. That's probably because the shared library can only be used by the root account. – CSLearner May 07 '14 at 20:23
  • 1
    That doesn't seem likely, sounds like you've misunderstood something. You might need to run the final `make install` step as root but not compile anything as root. – Jonathan Wakely May 07 '14 at 21:21
1

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/

whjiang
  • 11
  • 1
1

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!

Urdojo
  • 11
  • 1