【问题标题】:mex linker not finding mexFunction symbolmex 链接器没有找到 mexFunction 符号
【发布时间】:2013-06-19 20:06:53
【问题描述】:

直到最近,我都能够在我的 mac osx 10.8.4 上很好地编译 mex 函数 但现在它给了我如下错误(为方便起见,我已经包含了整个 -v 调用):

**************************************************************************
Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected. 
Using -compatibleArrayDims. In the future, MATLAB will require
the use of -largeArrayDims and remove the -compatibleArrayDims
option. For more information, see:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-    
api.html
**************************************************************************

-> mexopts.sh sourced from directory (DIR = .)
 FILE = /Users/munanxu/Dropbox/Code/CUDA/mexThomasTDM/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /Applications/MATLAB_R2013a.app
->    CC                    = xcrun  -sdk macosx10.7  clang
->    CC flags:
         CFLAGS             = -fno-common -arch x86_64 -isysroot   
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS
X10.7.sdk -mmacosx-version-min=10.7  -fexceptions
     CDEBUGFLAGS        = -g
     COPTIMFLAGS        = -O2 -DNDEBUG
     CLIBS              = -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx -lmex -lmat - 
     lstdc++
     arguments          =  -DMX_COMPAT_32
->    CXX                   = xcrun  -sdk macosx10.7  clang++
->    CXX flags:
      CXXFLAGS           = -fno-common -fexceptions -arch x86_64 -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX
10.7.sdk -mmacosx-version-min=10.7
     CXXDEBUGFLAGS      = -g
     CXXOPTIMFLAGS      = -O2 -DNDEBUG
     CXXLIBS            = -L/Applications/MATLAB_R2013a.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_R2013a.app/bin/maci64 -lmx -lmex -lmat -L    
-lgfortran -L -lgfortranbegin
     arguments          =  -DMX_COMPAT_32
->    LD                    = xcrun -sdk macosx10.7 clang
->    Link flags:
     LDFLAGS            = -arch x86_64 -Wl,-        
syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -bundle -Wl,-  
exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map
     LDDEBUGFLAGS       = -g
     LDOPTIMFLAGS       = -O
     LDEXTENSION        = .mexmaci64
     arguments          = 
->    LDCXX                 = 
->    Link flags:
     LDCXXFLAGS         = 
     LDCXXDEBUGFLAGS    = 
     LDCXXOPTIMFLAGS    = 
     LDCXXEXTENSION     = 
     arguments          = 
----------------------------------------------------------------

-> xcrun -sdk macosx10.7 clang -g -arch x86_64 -Wl,-  

syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2013a.app/extern/lib/maci64/mexFunction.map -o  
"inputsTest.mexmaci64"   "inputsTest.o"  -L/Applications/MATLAB_R2013a.app/bin/maci64 -lmx 
-lmex -lmat -lstdc++

Undefined symbols for architecture x86_64:
    "_mexFunction", referenced from:
     -exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64

我已将原始 mexopts.sh 文件复制到本地目录,以确保 mex 编译器使用正确的版本。我之前也使用 g++ 编译过我的 cpp 文件,只是为了确保代码是为 x86_64 架构本地编译的。但是,当我尝试使用 mex 编译器进行编译和链接时,会出现相同的结果。 关于这里可能发生的事情的任何想法?似乎人们以前遇到过这个问题,但主要是缺少库或定义。我已经在我的源文件中明确定义了一个 mexFunction。

【问题讨论】:

  • 另外,这不是这个特定文件独有的,似乎只影响我的 osx 机器。我尝试了许多不同的正确源文件来发现相同的错误,并且可以在 Windows 上正常编译。
  • 如何再次运行mex -setup 以重新创建mexopts.sh 文件,并删除任何本地版本。我没有 Mac,所以我不知道这是否重要,但请确保您的系统有兼容的编译器:mathworks.com/support/compilers/R2013a/index.html?sec=maci64

标签: matlab linker mex


【解决方案1】:

我认为 Amro 是正确的,我会将此作为评论,但它有点大,我为 clang command line options to select target CPU 找到这个

Registered Targets:
 alpha    - Alpha [experimental]
 arm      - ARM
 bfin     - Analog Devices Blackfin [experimental]
 c        - C backend ... ...
 mblaze   - MBlaze
 mips     - Mips ...
 msp430   - MSP430 [experimental] ...
 thumb    - Thumb
 x86      - 32-bit X86: Pentium-Pro and above
 x86-64   - 64-bit X86: EM64T and AMD64
 xcore    - XCoreI'm thinking Amro is correct:

-arch x86-64 是正确的命令行开关,而不是 x86_64

【讨论】:

  • 应该是。我正在运行 xcode 4.6,我的 cpu 是沙桥 i7。
  • 抱歉,我的意思是x86-64 而不是x86_64
  • 通常你不应该手动编辑这些东西,mex -setup 应该找出正确的标志(假设你选择了支持的编译器)。问题是是否支持clang 还是需要gcc?我听说 Xcode 现在默认带有 clang..
猜你喜欢
  • 2015-12-23
  • 2014-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-08
  • 1970-01-01
  • 2011-04-11
  • 2012-06-22
相关资源
最近更新 更多