“Symbols not found for Architecture x86_64” for a

2019-07-29 11:33发布

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.

Some basic information:

  • I can compile yprime.c and other MEX files that do not use the CPLEX API
  • I am using MATLAB 2011b on Mac OSX 10.7.2
  • I am using the GCC 4.2 package included in XCode 4.2.
  • I already applied the XCode 4.2 Patch for MATLAB

I would greatly appreciate any advice people may have. I'm including a verbose error report below.

-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
   FILE = /Users/berk/.matlab/R2011b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /Applications/MATLAB_R2011b.app
->    CC                    = llvm-gcc-4.2
->    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
->    CXX                   = llvm-g++-4.2
->    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
->    FC                    = gfortran
->    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
->    LD                    = llvm-gcc-4.2
->    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          = 
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          = 
----------------------------------------------------------------

-> 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
-> 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.

标签: c matlab mex cplex
1条回答
贼婆χ
2楼-- · 2019-07-29 12:06

You seem to be missing -lcplex or the relevant linking instruction for cplex on your system.

The User manual says the correct include and linking parameters are in readme.html of your cplex distribution, along with sample projects and makefiles.

From Using Cplex with Matlab it says you have specify the full library linking path and include path. Depending on what you are doing you may need to also specify -lilocplex to mex.

E.g. mex -I/cplex_include_fullpath -L/cplex_library_fullpath -lcplex file.c

查看更多
登录 后发表回答