How to provide Matlab with the old gcc version it wants?

非 Y 不嫁゛ 提交于 2019-12-05 22:10:13

问题


On my computer I have Ubuntu 10.10 with gcc 4.4.4. I try to compile some mex files which use CUDA and I get following error message:

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

I assume by linking Matlab with gcc 4.2.3 I can get rid of the error, but I don't know how to do it.

mex -setup gives me following options:

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:


I solved it by changing my mexopts.sh file, in ~/matlab/R2009b/mexopts.sh (change with your matlab version)

Find your architecture (for me it's glnxa64), and change it like this:

        ;;
    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'

PS: you also need to install the right version of gcc



来源:https://stackoverflow.com/questions/8524235/how-to-provide-matlab-with-the-old-gcc-version-it-wants

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!