{"id":27,"date":"2011-05-21T19:52:37","date_gmt":"2011-05-22T00:52:37","guid":{"rendered":"http:\/\/www.matthewcroberts.com\/?page_id=27"},"modified":"2011-05-21T19:52:37","modified_gmt":"2011-05-22T00:52:37","slug":"q3-why-wont-mex-work","status":"publish","type":"page","link":"http:\/\/www.matthewcroberts.com\/?page_id=27","title":{"rendered":"Q3: Why won&#8217;t MEX work?"},"content":{"rendered":"<p><span style=\"font-size: medium;\">3. Why can&#8217;t I compile FORTRAN90\/95 source code using the MEX command?<\/span><\/p>\n<p>(This information has only been tested on Win32 using DVF6.x. On other platforms, mileage may vary.)<\/p>\n<p>R13 (v6.5)<\/p>\n<p>The Mathworks have finally updated mex.bat to handle .f90 files properly, however, they have specified compiler options that cause many Fortran9x files that worked perfectly with R11 and R12 to fail. You will need to alter your df66opts.bat file located at<a href=\"file:\/\/\/c:\/matlab6p5\/bin\/win32\/mexopts\/\">c:\\matlab6p5\\bin\\win32\\mexopts\\<\/a> and then run\u00a0<span style=\"font-family: Courier;\">&gt;&gt;mex -setup<\/span> again<\/p>\n<p>If you examine your mexopts.bat file, you will find variables called OPTIMFLAGS and COMPFLAGS that look like<\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set OPTIMFLAGS=\/MD -Ox -DNDEBUG<\/span><\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set COMPFLAGS=\/fpp:&#8221;\/m \/S%MATLAB%\/extern\/include&#8221; -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE \/fixed<\/span><\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set DEBUGFLAGS=\/MDd -Zi<\/span><\/p>\n<p>Replace these lines with:<\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set OPTIMFLAGS=\/MT -Ox -DNDEBUG<\/span><\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set COMPFLAGS=\/fpp:&#8221;\/m \/S%MATLAB%\/extern\/include&#8221; -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE<\/span><\/p>\n<p><span style=\"font-family: Fixedsys; font-size: x-small;\">set DEBUGFLAGS=\/MTd -Zi<\/span><\/p>\n<p>(delete \/fixed and change \/MD -&gt; \/MT and \/MDd -&gt; \/MTd) You can see my\u00a0<a href=\"http:\/\/aede.osu.edu\/people\/roberts.628\/papers\/research\/fmex\/files\/r13_df66opts.bat.txt\">df66opts.bat<\/a> for more details.<\/p>\n<p><span style=\"text-decoration: underline;\">R12 (v6) <\/span><\/p>\n<p>(This was submitted to me by Rob Brendel, I haven&#8217;t tried it yet, as I don&#8217;t have R12)<\/p>\n<p>Make changes, as above, to lines 1216, 1283 and 1618 of\u00a0<span style=\"font-family: Courier;\">c:\\matlab\\bin\\mex.bat .<\/span><\/p>\n<p>That should work just fine.<\/p>\n<p><span style=\"text-decoration: underline;\">R11 (version 5.x)<\/span><\/p>\n<p>Basically the problem is that\u00a0<span style=\"font-family: Courier;\">mex.bat<\/span> doesn&#8217;t recognize files with extension<span style=\"font-family: Courier;\"> .f90<\/span> as being source files, it thinks that they are object files and passes them straight to the linker. This is obviously problematic. This change will make your F90 code work fine:<\/p>\n<p>(1) open\u00a0<span style=\"font-family: Courier;\">c:\\matlab\\bin\\mex.bat<\/span> using notepad (or pico or emacs, for your *NIXers)<br \/>\n(2) line 2338 is:<br \/>\n<span style=\"font-family: Courier;\"> if ($EXTENSION =~ \/(c|f|cc|cxx|cpp|for)$\/i ) {<br \/>\n<\/span>change it to<br \/>\n<span style=\"font-family: Courier;\"> if ($EXTENSION =~ \/(c|f|cc|cxx|cpp|for|f90)$\/i ) {<br \/>\n<\/span>(notice the &#8220;|f90&#8221;?)<\/p>\n<p>And that is all you will need! You should be able to run just fine.<\/p>\n<p>&nbsp;<\/p>\n<p>This page was last updated on\u00a028 August 2006 11:00\u00a0.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3. Why can&#8217;t I compile FORTRAN90\/95 source code using the MEX command? (This information has only been tested on Win32 using DVF6.x. On other platforms, mileage may vary.) R13 (v6.5) The Mathworks have finally updated mex.bat to handle .f90 files properly, however, they have specified compiler options that cause many Fortran9x files that worked perfectly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":24,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-27","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/pages\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":0,"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/pages\/27\/revisions"}],"up":[{"embeddable":true,"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=\/wp\/v2\/pages\/24"}],"wp:attachment":[{"href":"http:\/\/www.matthewcroberts.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}