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

后端 未结 8 1270
半阙折子戏
半阙折子戏 2020-12-01 12:55

Now mex in MATLAB 2012a only officially supports gcc 4.4.6 but I want to use gcc 4.7 at my own risk. Now If I compile something with mex directly, it will complain that

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 13:36

    It's a late answer, but I believe the cleanest, most Mathworks-approved and least invasive solution is to edit the .matlab7rc.sh script. This is a script used by the matlab script when you start MATLAB under UNIX-like systems. (See http://www.mathworks.ch/ch/help/matlab/ref/matlabunix.html)

    Copy that script (found under {matlabroot}/bin) to the root of your project, or to your home directory. Then tell MATLAB to first search in the system directories for the C++ libraries, instead of its own directories. On my system I changed line 191:

    191c191
    <       LDPATH_PREFIX='/usr/lib/x86_64-linux-gnu'
    ---
    >       LDPATH_PREFIX=''
    

    (Simply setting LD_LIBRARY_PATH to the empty string is not a good solution, because that will prevent you from loading other third-party libraries.)

    When this is done you might get the following message when running mex:

    /usr/bin/ld: cannot find -lstdc++
    

    This usually means that g++ is not installed. On a Debian-like system, run:

    sudo apt-get install g++
    

    From here on, you might still get an annoying warning about using a version of gcc beyond what is officially supported, but that is harmless and can be ignored.

提交回复
热议问题