如何为Matlab提供它所需的旧版gcc版本?

8

我的电脑上安装了Ubuntu 10.10和gcc 4.4.4。我尝试编译一些使用CUDA的mex文件,但出现以下错误消息:

>> cns_build('hmax')
compiling...
/home/leMe/hmax/cns/source/common_dec.h(54): warning: omission of exception specification is incompatible with previous function "operator new(size_t)"
/usr/include/c++/4.4/new(91): here
/home/leMe/hmax/cns/source/common_dec.h(55): warning: omission of exception specification is incompatible with previous function "operator new[](size_t)"
/usr/include/c++/4.4/new(92): here
/home/leMe/hmax/cns/source/common_dec.h(56): warning: omission of exception specification is incompatible with previous function "operator delete(void *)"
/usr/include/c++/4.4/new(93): here
/home/leMe/hmax/cns/source/common_dec.h(57): warning: omission of exception specification is incompatible with previous function "operator delete[](void *)"
/usr/include/c++/4.4/new(94): here

Segmentation fault
CUDA preprocessing [nvcc] failed
Warning: You are using gcc version "4.4.4-14ubuntu5)".  The version
         currently supported with MEX is "4.2.3".
         For a list of currently supported compilers see: 
         http://www.mathworks.com/support/compilers/current_release/
CPU compilation successful

我假设通过将Matlab与gcc 4.2.3连接,我可以消除这个错误,但是我不知道如何做到这一点。 mex -setup 给我以下选项:
1: /home/leMe/Matlab/bin/gccopts.sh : 
      Template Options file for building gcc MEX-files

  2: /home/leMe/Matlab/bin/mexopts.sh : 
      Template Options file for building MEX-files via the system ANSI compiler
1个回答

10

我通过更改位于~/matlab/R2009b/mexopts.sh(请根据您的Matlab版本进行更改)中的mexopts.sh文件来解决了这个问题。

找到您的架构(对我而言是glnxa64),并像这样进行更改:

        ;;
    glnxa64) #<----------------------- FIND THIS
        RPATH="-Wl,-rpath-link,$TMW_ROOT/bin/$Arch"
        # StorageVersion: 1.0
        # CkeyName: GNU C
        # CkeyManufacturer: GNU
        # CkeyLanguage: C
        # CkeyVersion:
        CC='gcc-4.1' #<---------------------------------- CHANGE HERE
        CFLAGS='-ansi -D_GNU_SOURCE'
        CFLAGS="$CFLAGS  -fexceptions"
        CFLAGS="$CFLAGS -fPIC -fno-omit-frame-pointer -pthread"
        CLIBS="$RPATH $MLIBS -lm"
        COPTIMFLAGS='-O -DNDEBUG'
        CDEBUGFLAGS='-g'
        CLIBS="$CLIBS -lstdc++"
        #
        # C++keyName: GNU C++
        # C++keyManufacturer: GNU
        # C++keyLanguage: C++
        # C++keyVersion: 
        CXX='g++-4.1' #<---------------------------------- CHANGE HERE
        CXXFLAGS='-ansi -D_GNU_SOURCE'
        CXXFLAGS="$CXXFLAGS -fPIC -fno-omit-frame-pointer -pthread"
        CXXLIBS="$RPATH $MLIBS -lm"
        CXXOPTIMFLAGS='-O -DNDEBUG'
        CXXDEBUGFLAGS='-g'

另外需要安装正确版本的gcc。


我无法安装gcc4.2.3。我会在解决这个问题后尝试您的答案。 - Framester
我发现我需要将/Applications/MATLAB_R2013a_Student.app/bin/mexopts.sh复制到~/.matlab/R2013a,并且我需要将maci64CC更改。 - Rose Perrone

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接