Compiling mex files on 64bit Linux using Student MATLAB
The student version of MATLAB is a bargain since it only costs $99 (or less than £50 for those of us in the UK) and it comes complete with several toolboxes including symbolic maths, statistics and optimisation. Most of it is identical to the full academic version which would cost well over a thousand pounds if you bought all of the toolboxes included in the student version. The only place where it is ‘crippled’ is within Simulink since your Simulink models are limited to 1000 blocks. There are one or two other differences too and I refer you to the amazon page for full details (Amazon is also the cheapest place I could find for Student MATLAB by the way).
One problem with the student version of MATLAB though is the fact that they only supply a 32 bit version. This was potentially a big problem for a friend of mine since he has a 64bit Linux machine with 4Gb of RAM. Fortunately, the 32bit version installs OK on 64bit Linux but the result is completely unsupported by Mathworks. Fair enough….It works and he is (mostly) happy since he gets a lot of functionality for his money.
One thing that definitely didn’t work though was compiling mex files. No matter how hard we tried we simply could not get it to work which made me look bad because I am supposed to be ‘The MATLAB guy’ around here. Well, sometimes it’s not what you know but who you know that counts and I know a LOT of MATLAB users. One of them has provided a fix but doesn’t want his name plastered all over Walking Randomly. So, thanks to Mr Anonymous we got mex files working on Student MATLAB 2009a running on 64bit Linux and this is how we did it.
Get a simple mex file and try to compile it. You’ll probably get this error.
/usr/bin/ld: cannot find -lmx
The way to get around that is to run the following command in MATLAB just before you try to compile a mex file
setenv('MATLAB_ARCH', 'glnx86') (IN MATLAB)
That gets you a little further but you’ll next be hit by
/usr/bin/ld: cannot find -lstdc++
To fix this you need to find your mexopts.sh file and change the line
CLIBS="$CLIBS -L/home/paul/matlab/R2009a-student/sys/os/glnx86 -lstdc++"
obviously, you’ll need to change /home/paul/matlab to wherever you actually installed MATLAB.
Your next step is to do the following in a bash prompt
ln -s /home/paul/matlab/R2009a-student/sys/os/glnx86/libstdc++.so.6 \ /home/paul/matlab/R2009a-student/sys/os/glnx86/libstdc++.so
again – substituting wherever you installed MATLAB for /home/paul/matlab
Paul was running Ubuntu 9.04 and he got the following error at some point (I can’t remember where)
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
which was fixed by
sudo apt-get install libc6-dev-i386
That’s pretty much it. You should now be able to compile mex files. Hope this helps someone out there.