MATLAB: Do I receive the error “undefined symbol: __gxx_personality_v0” when I try to run a C++ MEX-file under MATLAB 6.1 (R12.1)

__gxx_personality_v0ccxxlinuxMATLABmexplus

Why do I receive the following error when I try to run a C++ MEX-file under MATLAB 6.1 (R12.1)?
Unable to load mex file:
/home/chenhon2/work/wk/mfiles/SingleFit.mexglx.
/home/chenhon2/work/wk/mfiles/SingleFit.mexglx: undefined symbol:
__gxx_personality_v0
??? Invalid MEX-file

Best Answer

Some versions of LINUX need to link against certain C++ libraries to resolve undefined symbols when compiling C++ code.
The easiest way to do this is to use g++ to link the MEX-file. In MATLAB 6.5 (R13), this is automatically done by the mex script when it detects a C++ source file.
In earlier versions of MATLAB, you needed to specify a different option file to use when compiling C++ files. The name of the C++ options file to use is cxxopts.sh. For example, to compile your MEX-file from within MATLAB 6.1 (R12.1) you would use the following code:
eval(['mex -v -f ' matlabroot '/bin/cxxopts.sh your_mex_file.C'])