Mar 20, 2016

mex file using different 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:
You can find it like this:
$/sbin/ldconfig -p | grep stdc++ (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/ (libc6) => /usr/lib/i386-linux-gnu/

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

Many suggestion was offered. I am listing them here:

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

2. Edit the script inside the MATLAB/bin/ directory
Add the location of the newly installed file into the following path.


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


4. Change the system variable LD_LIBRARY_PATH

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/ version `GLIBCXX_3.4.20' not found
    ./a.out: /usr/lib/ version `CXXABI_1.3.8' not found
This means the linker found /usr/lib/ 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: