Using clang for cpp/cc compile


我的猫是最可爱的猫 : 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++

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容