title: Compiling a MEX file using object files in another folder
body: <p>I'm writing some MATLAB code, and I want to use some optimized C routines.  I have the C source code, and it works just fine.  I've created a MEX file and am capable of compiling it provided that it is in the same folder as the optimized C routines.  However, I want to be able to distribute this code to others on various platforms.  Since MEX files are binaries, each individual must (likely) recompile on their own machines.  That is fine, but I want to make the process as painless as possible.</p>
  
  <p>Currently, if all of the files are in the same directory, then calling something like</p>
  
  <pre><code>mex mexfile.c other1.o other2.o other3.o
  </code></pre>
  
  <p>from that directory works just fine as you would expect.  For organizational purposes, however, I'd like for the C code to be in its own (sub)directory, say <code>code</code>.  Unfortunately, if I structure things like this, the <code>mex</code> command errors out (the errors differ based on the different things that I've tried).  I've tried things like</p>
  
  <pre><code>mex mexfile.c code/other1.o code/other2.o code/other3.o
  </code></pre>
  
  <p>and the <code>-Ipathname</code> and <code>-Lfolder</code> options on the <code>mex</code> command, but these haven't worked for me.  I would think that there has to be a simple way to do what I'm wanting to do, but I just can't find the appropriate documentation or figure it out myself.  Any help would be appreciated.</p>