## Compiling mex files on 64bit Linux using Student MATLAB

December 3rd, 2009 | Categories: Linux, matlab, programming | Tags:

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 -lstdc++"

to

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.

1. Thanks, that saved me a lot of time!

2. Thanks so far for the help! But I still get the following errors:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.1.3/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.1.3/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.1.3/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.1.3/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

What to do?

3. Hi daniel

Which version of matlab and what Linux distro?

4. 32bit student version Matlab 7.10.0 (R2010a)
and
64bit Kubuntu 10.10 Maverick with 2.6.35-22-generic kernel

5. 32bit student version Matlab 7.10.0.499 (R2010a)
and
64bit Kubuntu Maverick 10.10 with 2.6.35-22-generic kernel

6. Hi Daniel

It’s been a while since I looked at this and I no longer have access to the system that I based the blog post on. However, could you try doing the following please?

sudo apt-get install ia32-libs
sudo apt-get install lib32gcc1

Does that help at all?

Cheers,
Mike

7. Mike, it doesn’t work for me :(
I’m running Matlab 7.9.0 (R2009b) 32-bit (glnx86) on openSUSE 11.0 (X86-64)
This is the Matlab command line output:

>> setenv(‘MATLAB_ARCH’, ‘glnx86′)
>> mex -glnx86 -I’/opt/glpk/include’ ‘glpkcc.cpp’ ‘/opt/glpk/lib/libglpk.a’

Warning: You are using gcc version “4.3.1”. The earliest gcc version supported
with mex is “4.1”. The latest version tested for use with mex is “4.2”.

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.3/libstdc++.so when searching for -lstdc++
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.3/libstdc++.a when searching for -lstdc++
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

mex: link of ‘ “glpkcc.mexglx”‘ failed.

??? Error using ==> mex at 221
Unable to complete successfully.

I’ve followed all the steps you mention, but it continues showing the same error.

8. Hi Nacho

That’s exactly the error that a lot of this post was written to correct. It worked for us.
We were using 32bit MATLAB 2009a on 64bit Ubuntu so the further your system deviates from this, the less likely these notes will work.

I’m sorry that I can’t suggest more.

Mike

9. Thanks! Worked for me. You saved me a lot of time.

10. Saved my life, thanks a lot.

11. Hey, does this description still work for Ubuntu 12.04 64bit and Matlab Student Version R2012a 32 bit?

Thanks,
Bunsen

12. No idea, sorry.