“在架构x86_64中找不到符号”,表示在C中使用CPLEX API的MEX文件

时间:2012-03-17 20:34:33

标签: c matlab mex cplex

我目前正在MATLAB中编写MEX文件,该文件使用C语言中的CPLEX API来解决线性编程问题。不幸的是,当我尝试编译并且我不知道如何解决它时,我遇到了“找不到架构x86_64的符号”问题。

一些基本信息:

  • 我可以编译yprime.c和其他不使用CPLEX API的MEX文件
  • 我在Mac OSX 10.7.2上使用MATLAB 2011b
  • 我使用的是XCode 4.2中包含的GCC 4.2软件包。
  • 我已经应用了XCode 4.2 Patch for MATLAB

我非常感谢人们可能提出的任何建议。我在下面提供了一份详细的错误报告。

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

1 个答案:

答案 0 :(得分:2)

您似乎缺少-lcplex或系统上cplex的相关链接说明。

用户手册说正确的包含和链接参数位于cplex发行版的readme.html中,以及示例项目和makefile。

Using Cplex with Matlab开始,它表示您已指定完整的库链接路径并包含路径。根据您的操作,您可能还需要为mex指定-lilocplex

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