Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT: There seems to be a much better way with MinGW; see my other answer.</strong></p> <p>You can compile a <code>.mex</code> file using <code>gcc</code> if you have <code>Matlab</code> installed, from the command line. Some might say it's a little tedious the first time.</p> <p>First things first - what Matlab do you use? if it's 64-bits, <code>MinGW</code> won't help you, because it's 32-bit. I will therefore show how to use <a href="http://mingw-w64.sourceforge.net/" rel="nofollow">MinGW-w64</a> instead. Understanding how to do this with 32-bit <code>MinGW</code> should be straightforward.</p> <ol> <li>Add <code>C:\MinGW-64\bin\</code> to your path. You won't regret this :)</li> <li><p>Compile your <code>.c</code> files using <code>gcc</code>:</p> <pre><code>x86_64-w64-mingw32-c++ -m64 -shared -I"C:\Program Files\MATLAB\R2010b\extern\include" -o bla.mexw64 -DMATLAB_MEX_FILE -Wl,--export-all-symbols *.cpp </code></pre></li> <li><p>This will result in a bunch of linker errors, such as</p> <pre><code>undefined reference to `mexErrMsgTxt' </code></pre> <p>To solve this problem, you'll have to create an import library which connects with <code>libmex.dll</code>, <code>libmx.dll</code>, <code>libmat.dll</code> and <code>libeng.dll</code> (you might have others, but these are the main ones)</p></li> <li><p>List the functions you're missing, and, well, guess what <code>dll</code> they're coming from. Hint: <code>mexErrMsgTxt</code> is from <code>libmex.dll</code>, because it starts with "mex"...</p></li> <li><p>For every <code>dll</code> you need to export, create a <code>.def</code> file containing </p> <pre><code>EXPORTS ... relevant function names go here, such as mexErrMsgTxt, matOpen, etc. </code></pre></li> <li><p>Execute the following command, to create import libraries:</p> <pre><code>x86_64-w64-mingw32-dlltool -d libmx.def --dllname libmx.dll -l libmx.a </code></pre> <p>(Same for the rest of the <code>.def</code> files)</p></li> <li><p>Now you're good to go!</p> <pre><code>x86_64-w64-mingw32-c++ -m64 -shared -I"C:\..." -DMATLAB_MEX_FILE -o bla.mexw64 -Wl,--export-all-symbols *.cpp libmex.a libmx.a libmat.a libeng.a </code></pre></li> </ol> <p>Things which can be done better - instead of <code>--export-all-symbol</code>, only export <code>mexFunction</code> (requires creating another <code>.def</code> file, or adding "<code>__declspec(dllexport)</code>" before <code>void mexFunction(...)</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload