title: Compiling C code for 64-bit Matlab on Intel MAC
body: <p>I need compile a piece of C code to be called from matlab (mex compiling).
    I am doing that on an intel mac and, since I am using Matlab's R2010a (7.10.0.499), I'd like to compile the C code into a version for 64-bits.
    For whatever reason, just doing mex with the -arch=maci64 option did not seem to work...</p>
  
  <p>As a way around, I am compiling the C code to a mexmaci64 file directly on the command line. 
    I used the gcc calls made by mex (with the -v option on) as a starting point.
    I managed to compile the C code to an object file, but it looks like I am not compiling the C code to the correct architecture.</p>
  
  <p>Does anyone know how to correct the gcc calls below so the C code gets compiled to 64-bits intel macs?</p>
  
  <p>Details are listed below.</p>
  
  <p>As always, any help greatly appreciated...</p>
  
  <p>Keep thirsty, my friends. :p</p>
  
  <p>G</p>
  
  <p>DETAILS:</p>
  
  <p>Here is how I did the compilation and linking:</p>
  
  <pre><code>gcc -c  -I/Applications/MATLAB_R2010a.app/extern/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -D MACVERSION  -DMX_COMPAT_32 -O3 -DNDEBUG  "BoxQP.c"
  
  gcc -O -bundle -Wl,-flat_namespace -undefined suppress -Wl,-exported_symbols_list,/Applications/MATLAB_R2010a.app/extern/lib/maci64/mexFunction.map -o  "BoxQP.mexmaci64"  BoxQP.o  -L/Applications/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
  </code></pre>
  
  <p>Here are the warnings I get:</p>
  
  <pre><code>ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmx.dylib, file is not of required architecture
  ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmex.dylib, file is not of required architecture
  ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmat.dylib, file is not of required architecture
  </code></pre>
  
  <p>Ignoring the warnings and calling the BoxQP function from matlab results in the following error message:</p>
  
  <pre><code>??? Invalid MEX-file '/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64':
  dlopen(/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64, 1): no suitable image found.  
  Did find: /Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64: mach-o, but wrong architecture.
  </code></pre>
  
  <p>PS: I tried changing the -DMX_COMPAT_32 flag to -DMX_COMPAT_64 but I do get the same warnings and same error...</p>
  
  <p>PPS: I guess it may be relevant to mention that I am using Mac OS X 10.5.8 (the "tropical"/plain-vanilla Leopard, i.e., not the snow Leopard).</p>
  
  <p>PPPS: The same happens with the yprime.c example provided by MATLAB</p>