美文网首页
Using clang for cpp/cc compile

Using clang for cpp/cc compile

作者: 大头菜turtle | 来源:发表于2019-10-11 14:45 被阅读0次

    我的猫是最可爱的猫 : D

    clang VS gcc

    when return boolean, such as:

    bool Init(){
        // do something 
        
    }
    

    in gcc you can return nothing, but in clang you must return a boolean value. Or clang will throw segmentation fault

    Code must be:

    bool Init(){
        // do something
        return true; //or return false
        
    }
    

    How to replace gcc with clang in unix

    • first install llvm and clang:

      sudo apt install llvm
      sudo apt insatll clang
      
    • change default c++

      for cpp:

      sudo update-alternatives --config c++
      
      There are 2 choices for the alternative c++ (providing /usr/bin/c++).
      
        Selection    Path              Priority   Status
      ------------------------------------------------------------
        0            /usr/bin/g++       20        auto mode
        1            /usr/bin/clang++   10        manual mode
      * 2            /usr/bin/g++       20        manual mod
      
      Press enter to keep the current choice[*], or type selection number: 1
      

      c in the same way:

      sudo update-alternatives --config cc
      There are 2 choices for the alternative cc (providing /usr/bin/cc).
      
        Selection    Path            Priority   Status
      ------------------------------------------------------------
        0            /usr/bin/gcc     20        auto mode
        1            /usr/bin/clang   10        manual mode
      * 2            /usr/bin/gcc     20        manual mode
      
      Press <enter> to keep the current choice[*], or type selection number: 1
      update-alternatives: using /usr/bin/clang to provide /usr/bin/cc (cc) in manual mode
      

      OK, Now you use clang instead of gcc/g++

    相关文章

      网友评论

          本文标题:Using clang for cpp/cc compile

          本文链接:https://www.haomeiwen.com/subject/mmgtmctx.html