title: "Symbols not found for Architecture x86_64" for a MEX file that uses the CPLEX API in C
body: <p>I'm currently writing a MEX file in MATLAB that uses the CPLEX API in C to solve linear programming problems. Unfortunately, I run into a "symbol(s) not found for architecture x86_64" problem when I attempt to compile and I have no idea of how to solve it. </p>
  
  <p>Some basic information:</p>
  
  <ul>
  <li>I can compile <code>yprime.c</code> and other MEX files that do not use the CPLEX API</li>
  <li>I am using MATLAB 2011b on Mac OSX 10.7.2 </li>
  <li>I am using the GCC 4.2 package included in XCode 4.2. </li>
  <li>I already applied the <a href="http://www.mathworks.com/support/solutions/en/data/1-FR6LXJ/" rel="nofollow">XCode 4.2 Patch for MATLAB</a></li>
  </ul>
  
  <p>I would greatly appreciate any advice people may have. I'm including a verbose error report below.</p>
  
  <pre><code>-&gt; mexopts.sh sourced from directory (DIR = $PREF_DIR)
     FILE = /Users/berk/.matlab/R2011b/mexopts.sh
  ----------------------------------------------------------------
  -&gt;    MATLAB                = /Applications/MATLAB_R2011b.app
  -&gt;    CC                    = llvm-gcc-4.2
  -&gt;    CC flags:
           CFLAGS             = -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5  -fexceptions -Wall
           CDEBUGFLAGS        = -g
           COPTIMFLAGS        = -O2 -DNDEBUG
           CLIBS              = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
           arguments          =  -DMX_COMPAT_32
  -&gt;    CXX                   = llvm-g++-4.2
  -&gt;    CXX flags:
           CXXFLAGS           = -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5
           CXXDEBUGFLAGS      = -g
           CXXOPTIMFLAGS      = -O2 -DNDEBUG
           CXXLIBS            = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
           arguments          =  -DMX_COMPAT_32
  -&gt;    FC                    = gfortran
  -&gt;    FC flags:
           FFLAGS             = -fexceptions -m64 -fbackslash
           FDEBUGFLAGS        = -g
           FOPTIMFLAGS        = -O
           FLIBS              = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
           arguments          =  -DMX_COMPAT_32
  -&gt;    LD                    = llvm-gcc-4.2
  -&gt;    Link flags:
           LDFLAGS            = -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map
           LDDEBUGFLAGS       = -g
           LDOPTIMFLAGS       = -O
           LDEXTENSION        = .mexmaci64
           arguments          = 
  -&gt;    LDCXX                 = 
  -&gt;    Link flags:
           LDCXXFLAGS         = 
           LDCXXDEBUGFLAGS    = 
           LDCXXOPTIMFLAGS    = 
           LDCXXEXTENSION     = 
           arguments          = 
  ----------------------------------------------------------------
  
  -&gt; llvm-gcc-4.2 -c  -I/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/include/ilcplex/ -I/Applications/MATLAB_R2011b.app/extern/include -I/Applications/MATLAB_R2011b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5  -fexceptions -Wall  -DMX_COMPAT_32 -O2 -DNDEBUG  "addcutsmx.c"
  
  addcutsmx.c:488:4: warning: "/*" within comment
  addcutsmx.c:37: warning: 'free_and_null' declared 'static' but never defined
  addcutsmx.c:38: warning: 'usage' declared 'static' but never defined
  -&gt; llvm-gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map -o  "addcutsmx.mexmaci64"  addcutsmx.o  -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
  
  Undefined symbols for architecture x86_64:
    "_CPXLopenCPLEX", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLcreateprob", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLchgobjsen", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLnewcols", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLaddrows", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLlpopt", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLsolution", referenced from:
        _mexFunction in addcutsmx.o
    "_CPXLgetbase", referenced from:
        _mexFunction in addcutsmx.o
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  
        mex: link of ' "addcutsmx.mexmaci64"' failed.
  
  Error using mex (line 206)
  Unable to complete successfully.
  </code></pre>