3

I am trying to compile matconvnet-1.0-beta20 with Matlab 2016a on Ubuntu 16.04. Initial phase of compilation works fine:

 untar('http://www.vlfeat.org/matconvnet/download/matconvnet-1.0-beta20.tar.gz') ;
 cd matconvnet-1.0-beta20
 run matlab/vl_compilenn

The error happens when I run vl_simplenn(network, image) which gives following error:

Invalid MEX-file '/home/matconvnet-1.0-beta20/matlab/mex/vl_nnconv.mexa64':
/usr/local/MATLAB/R2016a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version
`GLIBCXX_3.4.21' not found (required by /home/matconvnet-1.0-beta20/matlab/mex/vl_nnconv.mexa64)

To understand the cause of problem, I run /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBC which doesn't give any output bash: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: Permission denied Also more /usr/lib/x86_64-linux-gnu/libstdc++.so.6 gives no output:

******** /usr/lib/x86_64-linux-gnu/libstdc++.so.6: Not a text file ********

I did some research and found some possible solutions:

  1. http://it.mathworks.com/matlabcentral/newsreader/view_thread/162466

The problem is that MATLAB secretly changes LD_LIBRARY_PATH on startup to point to the MATLAB version of GLIBC++, so that GLIBC++ 3.4.9 can no longer be found. The solution is to modify matlab/bin/.matlab7rc.sh so that "LDPATH_PREFIX" contains the path to the version of GLIB installed with your compiler, then this is found before the matlab-supplied library.

so I edited /usr/local/MATLAB/R2016a/bin/.matlab7rc.sh and modified LDPATH_PREFIX='' in 195th line to LDPATH_PREFIX='/usr/lib/x86_64-linux-gnu'.

After applying this change, the problem still exist.

As suggested here, I copied .matlab7rc.sh to current working directory of project, but still error persist.

  1. https://askubuntu.com/questions/719028/version-glibcxx-3-4-21-not-found

According to first answer, running this command ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6
gives an error:

ln: failed to create symbolic link 'usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6': No such file or directory

Seems like second solution suggests changes of LD_PRELOAD path in .matlab7rc.sh, but it is not anywhere inside the file.

  1. How to tell mex to link with the libstdc++.so.6 in /usr/lib instead of the one in the MATLAB directory?

From Matlab directory in /usr/local/MATLAB/R2016a/bin$ I run export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/libstdc++.so.6

but the problem still exist.


Maybe there I didn't apply the solution in the correct way Or maybe there is another solution elsewhere that I didn't find. Please let me know, I am very confused!!!

Community
  • 1
  • 1
Sadegh
  • 865
  • 1
  • 23
  • 47
  • 2
    http://stackoverflow.com/questions/25929332/version-glibcxx-3-4-11-not-found-required-by-buildw-mexglx?rq=1 -> Seems like it is solved by deleting libstdc++.so.6 – Sadegh Jun 20 '16 at 12:00
  • I have had good results with just deleting the libstdc++ file that comes with MATLAB, as long as you have a newer version of GCC installed on your system. – Cris Luengo Apr 24 '18 at 20:50
  • ...of course renaming or moving it instead of deleting it is a lot safer, so you can put it back if things go sour. :) – Cris Luengo Apr 24 '18 at 20:51

3 Answers3

6

You need before execute (matlab in my case) add path of library:

In console execute this:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 matlab
2

I had the same problem. In my case, to solve it, I first ran "locate" to list all the possible versions of the library in the system.

locate libstdc++

As an example, I report the result on my system

enter image description here

I then set the most recent version of "lib" by exporting the environment variable:

export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21"

So, the fullpath of the library to be set depends on where it is allocated in your system.

-1

There are 2 possible solutions:

  1. LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/libstdc++.so.6

  2. Install this package:

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    
  3. MAYBE the second solution you mentioned really works, but you have done it before. So you cannot operate in the same way again because you have ever linked /usr/lib/x86_64-linux-gnu/libstdc++.so.6 to usr/local/MATLAB/R2014a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6. TRY rebooting?

Also, you use MATLAB R2016a, but this command applies to R2014a. Was it that you ignore this point?

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146