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
You can modify ~/.matlab/R2012a/mexopts.sh that generated after doing mex -setup by adding a line in glnx86 section:
~/.matlab/R2012a/mexopts.sh
mex -setup
LD_LIBRARY_PATH='/usr/lib:$LD_LIBRARY_PATH'
or in glnx64:
LD_LIBRARY_PATH='/usr/lib64:$LD_LIBRARY_PATH'