【问题标题】:Matlab & Xcode 5 : "clang: link fails"Matlab & Xcode 5:“clang:链接失败”
【发布时间】:2014-09-27 19:02:09
【问题描述】:

我尝试使用 Xcode 5 在我的 MacBook Pro OS X 10.9 上安装 nfft package。 当我测试 nfft 包时,我必须使用以下命令编译一个 .c 文件:

fftw3Path='/Users/boyer/Documents/MATLAB/fftw-3.3.4/';
nfft3Path='/Users/boyer/Documents/MATLAB/nfft-3.2.3/';
Ipath=[' -I' nfft3Path 'include ' ' -I' nfft3Path 'applications/fastsum ' '-I' fftw3Path 'api ' '-I' nfft3Path 'matlab ' ];
Lpath=['-L' nfft3Path ' ' '-L' nfft3Path 'applications/fastsum' ' ' '-L' fftw3Path 'api' ];
command=sprintf(['mex -v -Dchar16_t=uint16_t ' Lpath ' ' Ipath ' -lfftw3 -lnfft3 nfftmex.c']);
eval(command)

这是我得到的答案:

Building with 'Xcode with Clang'. /usr/bin/xcrun -sdk macosx10.8 clang -c -Dchar16_t=uint16_t -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/include -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/applications/fastsum -I/Users/boyer/Documents/MATLAB/fftw-3.3.4/api -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/matlab -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/boyer/Documents/MATLAB/nfft-3.2.3/matlab/nfft/nfftmex.c -o /var/folders/_0/63lwd1z17j94w_7wgkrw3x700000gn/T//mex_2747778005296_34460/nfftmex.o /usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/_0/63lwd1z17j94w_7wgkrw3x700000gn/T//mex_2747778005296_34460/nfftmex.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" -lfftw3 -lnfft3 -L/Users/boyer/Documents/MATLAB/nfft-3.2.3/ -L/Users/boyer/Documents/MATLAB/nfft-3.2.3/applications/fastsum -L/Users/boyer/Documents/MATLAB/fftw-3.3.4/api -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o nfftmex.mexmaci64 Error using mex Undefined symbols for architecture x86_64: "_nfft_mex_get_int", referenced from: _mexFunction in nfftmex.o "_nfft_mex_install_mem_hooks", referenced from: _mexFunction in nfftmex.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

使用MatlabR2011b,我将mexopts.sh文件修改如下:

;;
    maci64)
#----------------------------------------------------------------------------
        #PATCH: MacOSX10.9
        CC='llvm-gcc'
        CXX='llvm-g++'
        SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'
        MACOSX_DEPLOYMENT_TARGET='10.9'
        ARCHS='x86_64'

        # StorageVersion: 1.0
        # CkeyName: GNU C
        # CkeyManufacturer: GNU
        # CkeyLanguage: C
        # CkeyVersion:
        CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
        #CFLAGS='-ansi -D_GNU_SOURCE'
        CFLAGS="$CFLAGS -std=c99"
        CFLAGS="$CFLAGS  -fexceptions"
        CLIBS="$MLIBS"
        COPTIMFLAGS='-O2 -DNDEBUG'
        CDEBUGFLAGS='-g'
        #
        CLIBS="$CLIBS -lstdc++"
        # C++keyName: GNU C++
        # C++keyManufacturer: GNU
        # C++keyLanguage: C++
        # C++keyVersion: 
        CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
        CXXFLAGS='-ansi -D_GNU_SOURCE'
        CXXLIBS="$MLIBS -lstdc++"
        CXXOPTIMFLAGS='-O2 -DNDEBUG'
        CXXDEBUGFLAGS='-g'

我还尝试通过 -std=libstdc++ 更改库 -lstdc++。没有什么能解决问题。

然后我用了MatlabR2014a,也出现同样的错误(但是这个版本,我们不能修改mexopts.sh,好像已经被mex_C_maci64.xml代替了)。

我想也许我会安装另一个太糟糕的 c 编译器,因为至少 MatlabR2014a 应该与 Xcode5 兼容。

如果您有任何建议,请提前感谢您。

【问题讨论】:

    标签: xcode macos matlab


    【解决方案1】:

    当我试图在 OSX 上安装软件时,我讨厌把头撞到砖墙上,所以我将 homebrew 用于 ImageMagick、GNU coreutils、gawk、sed、ffmpeg、gnuplot、GNU parallel、REDIS、opencv、jhead、p7zip 等.

    nfft 似乎有一个公式,所以我怀疑您需要做的就是安装homebrew,通过转到their website 并按照简单的一行指令进行操作。然后你可以tap进入存储库的科学分支并像这样安装nfft

    brew tap homebrew/science
    brew install nfft
    

    你就完了!如果有任何问题,请运行

    brew doctor
    

    【讨论】:

      【解决方案2】:

      感谢您的帮助和有用的建议。现在,在安装 nfft 包时(在 make 和 make install 之前)应用以下命令似乎可以工作:

      ./configure --with-fftw3='/usr/local' --with-fftw3-libdir='/usr/local/lib' --with-fftw3-includedir='/usr/local/include' --with-matlab='/Applications/MATLAB_R2014a.app' --with-matlab-fftw3-libdir='/usr/local/lib'
      

      另外评论:即使OS X的版本是10.9,matlab还是选择10.8sdk。为避免这种情况,您可以编辑文件 mex_C_maci64.xml,并反转 2 行代码:

      <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" />
                        <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
                        <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.7.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.9.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.8.sdk" />
      

      而不是

      <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" />
                        <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" />
                        <dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.7.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.8.sdk" />
                        <cmdReturns name="find $$ -name MacOSX10.9.sdk" />
      

      结束

      希望它可以帮助别人。再次感谢您的回答。

      【讨论】:

        猜你喜欢
        • 2019-04-28
        • 2012-01-26
        • 2016-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-15
        • 1970-01-01
        • 2016-10-18
        相关资源
        最近更新 更多