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

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容