Mar 20, 2016

mex file using different libstd++.so.6 issue?

A common problem of compiling a new mex file is that it was compiled for different g++ version.

For example if you install a newer version of gcc library under the directory:
/usr/lib/x86_64-linux-gnu
 
You can find it like this:
$/sbin/ldconfig -p | grep stdc++
    libstdc++.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
    libstdc++.so.6 (libc6) => /usr/lib/i386-linux-gnu/libstdc++.so.6


When you build the mex file it uses the prefix of the already installed stdc++ path and prepends it for libstdc++.so.6 file. For example usually, it puts -L/usr/local/MATLAB/R2012a/sys/os/glnx86
Hence even though your newly installed the libstdc++.so.6 file is in
/usr/lib/x86_64-linux-gnu the invoked mex file will try to pick the libstdc++.so.6 from /local/MATLAB/R2015b/sys/os/gnlx86/

Many suggestion was offered. I am listing them here:

1. Modify the MATLAB/R2015b/bin/mexopts.sh
=================================================== 
Reference 
Open the MATLAB/R2015b/bin/mexopts.sh
I commented out the -lstdc++
Then the compiled version of the mex file linked to the newly installed stdc++.

===================================================
 
2. Edit the .matlab7rc.sh script inside the MATLAB/bin/ directory
===================================================
Add the location of the newly installed libstdc++.so.6 file into the following path.
LDPATH_PREFIX='/usr/lib/x86_64-linux-gnu/'

===================================================


3. Directory changing LD_LIBRARY_PATH from the matlab console
===================================================
MatlabPath = getenv('LD_LIBRARY_PATH')
setenv('LD_LIBRARY_PATH',matlabpath)

===================================================


4. Change the system variable LD_LIBRARY_PATH
===================================================
Reference

If you already have an older version of libstdc++ installed then the error might look like one of the following instead:
    ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
    ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
    
This means the linker found /usr/lib/libstdc++.so.6 but that library belongs to an older version of GCC than was used to compile and link the program a.out (or some part of it). The program depends on code defined in the newer libstdc++ that belongs to the newer version of GCC, so the linker must be told how to find the newer libstdc++ shared library.
The simplest way to fix this is to use the LD_LIBRARY_PATH environment variable, which is a colon-separated list of directories in which the linker will search for shared libraries:

    export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH 
 
================================================================================================ 
 

No comments:

Orpheus and Eurydice