Error: version `GLIBCXX_3.4.21' not found
<p>I am trying to compile matconvnet-1.0-beta20 with Matlab 2016a on Ubuntu 16.04. Initial phase of compilation works fine:</p>

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

<p>The error happens when I run <code>vl_simplenn(network, image)</code> which gives following error:</p>

<pre><code>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)
</code></pre>

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

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

<p>I did some research and found some possible solutions:</p>

<ol>
<li><a href="http://it.mathworks.com/matlabcentral/newsreader/view_thread/162466" rel="nofollow noreferrer">http://it.mathworks.com/matlabcentral/newsreader/view_thread/162466</a></li>
</ol>

<blockquote>
  <p>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. <strong>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</strong>, then this is found before the
  matlab-supplied library.</p>
</blockquote>

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

<p>After applying this change, the problem still exist.</p>

<p>As suggested <a href="https://stackoverflow.com/a/20288112/5510001">here</a>, I copied .matlab7rc.sh to current working directory of project, but still error persist.</p>

<ol start="2">
<li><a href="https://askubuntu.com/questions/719028/version-glibcxx-3-4-21-not-found">https://askubuntu.com/questions/719028/version-glibcxx-3-4-21-not-found</a></li>
</ol>

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

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

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

<ol start="3">
<li><a href="https://stackoverflow.com/questions/9959306/how-to-tell-mex-to-link-with-the-libstdc-so-6-in-usr-lib-instead-of-the-one-i">How to tell mex to link with the libstdc++.so.6 in /usr/lib instead of the one in the MATLAB directory?</a></li>
</ol>

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

<p>but the problem still exist.</p>

<hr>

<p>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!!!</p>