{"id":1959,"date":"2009-12-03T18:36:54","date_gmt":"2009-12-03T17:36:54","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=1959"},"modified":"2009-12-05T22:31:33","modified_gmt":"2009-12-05T21:31:33","slug":"compiling-mex-files-on-64bit-linux-using-student-matlab","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=1959","title":{"rendered":"Compiling mex files on 64bit Linux using Student MATLAB"},"content":{"rendered":"<p>The student version of MATLAB is a bargain since it only costs $99 (or <a href=\"http:\/\/www.amazon.co.uk\/gp\/product\/0979223997?ie=UTF8&amp;tag=walkingrandom-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0979223997\">less than \u00a350 for those of us in the UK<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border:none !important; margin:0px !important;\" src=\"http:\/\/www.assoc-amazon.co.uk\/e\/ir?t=walkingrandom-21&amp;l=as2&amp;o=2&amp;a=0979223997\" border=\"0\" alt=\"\" width=\"1\" height=\"1\" \/>) and it comes complete with several toolboxes including symbolic maths, statistics and optimisation.\u00a0 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.\u00a0 The only place where it is &#8216;crippled&#8217; is within Simulink since your Simulink models are limited to 1000 blocks.\u00a0 There are one or two other differences too and I refer you to <a href=\"http:\/\/www.amazon.co.uk\/gp\/product\/0979223997?ie=UTF8&amp;tag=walkingrandom-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0979223997\">the amazon page<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border:none !important; margin:0px !important;\" src=\"http:\/\/www.assoc-amazon.co.uk\/e\/ir?t=walkingrandom-21&amp;l=as2&amp;o=2&amp;a=0979223997\" border=\"0\" alt=\"\" width=\"1\" height=\"1\" \/> for full details (Amazon is also the cheapest place I could find for Student MATLAB by the way).<\/p>\n<p>One problem with the student version of MATLAB though is the fact that they only supply a 32 bit version.\u00a0 This was potentially a big problem for a <a href=\"http:\/\/blog.crossedstreams.com\/\">friend of mine<\/a> since he has a 64bit Linux machine with 4Gb of RAM.\u00a0 Fortunately, the <a href=\"http:\/\/www.mathworks.com\/support\/solutions\/en\/data\/1-5UW63C\/index.html?product=ML&amp;solution=1-5UW63C\">32bit version installs OK on 64bit Linux<\/a> but the result is completely unsupported by Mathworks.\u00a0 Fair enough&#8230;.It works and he is (mostly) happy since he gets a lot of functionality for his money.<\/p>\n<p>One thing that definitely didn&#8217;t work though was compiling <a href=\"http:\/\/www.mathworks.com\/support\/tech-notes\/1600\/1605.html\">mex files<\/a>.\u00a0 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 &#8216;The MATLAB guy&#8217; around here.\u00a0 Well, sometimes it&#8217;s not what you know but who you know that counts and I know a LOT of MATLAB users.\u00a0 One of them has provided a fix but doesn&#8217;t want his name plastered all over Walking Randomly.\u00a0 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.<\/p>\n<p>Get a simple mex file and try to compile it.\u00a0 You&#8217;ll probably get this error.<\/p>\n<pre>\/usr\/bin\/ld: cannot find -lmx<\/pre>\n<p>The way to get around that is to run the following command in MATLAB just before you try to compile a mex file<\/p>\n<pre>setenv('MATLAB_ARCH', 'glnx86')   (IN MATLAB)<\/pre>\n<p>That gets you a little further but you&#8217;ll next be hit by<\/p>\n<pre>\/usr\/bin\/ld: cannot find -lstdc++<\/pre>\n<p>To fix this you need to find your mexopts.sh file and change the line<\/p>\n<pre>CLIBS=\"$CLIBS -lstdc++\"<\/pre>\n<p>to<\/p>\n<pre>CLIBS=\"$CLIBS -L\/home\/paul\/matlab\/R2009a-student\/sys\/os\/glnx86 -lstdc++\"<\/pre>\n<p>obviously, you&#8217;ll need to change \/home\/paul\/matlab to wherever you actually installed MATLAB.<\/p>\n<p>Your next step is to do the following in a bash prompt<\/p>\n<pre>ln -s \/home\/paul\/matlab\/R2009a-student\/sys\/os\/glnx86\/libstdc++.so.6 \\\r\n\/home\/paul\/matlab\/R2009a-student\/sys\/os\/glnx86\/libstdc++.so<\/pre>\n<p>again &#8211; substituting wherever you installed MATLAB for \/home\/paul\/matlab<\/p>\n<p>Paul was running Ubuntu 9.04 and he got the following error at some point (I can&#8217;t remember where)<\/p>\n<pre>\/usr\/include\/gnu\/stubs.h:7:27: error: gnu\/stubs-32.h: No such file or directory<\/pre>\n<p>which was fixed by<\/p>\n<pre>sudo apt-get install libc6-dev-i386<\/pre>\n<p>That&#8217;s pretty much it.  You should now be able to compile mex files.  Hope this helps someone out there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The student version of MATLAB is a bargain since it only costs $99 (or less than \u00a350 for those of us in the UK) and it comes complete with several toolboxes including symbolic maths, statistics and optimisation.\u00a0 Most of it is identical to the full academic version which would cost well over a thousand pounds [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,11,7],"tags":[],"class_list":["post-1959","post","type-post","status-publish","format-standard","hentry","category-linux","category-matlab","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-vB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1959"}],"version-history":[{"count":11,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1959\/revisions"}],"predecessor-version":[{"id":2002,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1959\/revisions\/2002"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}