skip to Main Content

I am trying to compile a C++ project on a PC with "Debian GNU/Linux 10". The project requires clang, so I installed it with:

sudo apt-get install clang

But I run into the following error:

Clang version must be at least 11, the version used is 7.0.1

How can I install clang 11?

Note: I do not want to install the entire LLVM package again. Just want to upgrade Clang from version 7 to 11, preferably via command-line.

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution after some searching. Here is what I did to make it work:

    1. Add the following lines to your /etc/apt/sources.list:
    deb http://apt.llvm.org/buster/ llvm-toolchain-buster main 
    deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster main 
    deb http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main 
    deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main 
    deb http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main 
    deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main
    
    1. Add signatures for these repos (otherwise apt-get update will complain in the next step)
    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
    
    1. Run apt-get update to add these new repos to the apt-get:
    sudo apt-get update
    
    1. Install clang-11:
    sudo apt-get install clang-11
    
    1. Make sure now "clang-11" is used by the compiler and not the older "clang":
    export CMAKE_C_COMPILER=clang-11
    export CMAKE_CXX_COMPILER=clang++-11
    
    1. Compile your project.
    2. Enjoy!

    For documentation: https://apt.llvm.org/


  2. I would suggest installing the latest stable 15

    1. Add the following lines to your /etc/apt/sources.list:
    deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye main
    deb-src http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye main
    # 15
    deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-15 main
    deb-src http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-15 main
    
    1. Add signatures for these repos (otherwise apt-get update will complain in the next step)
    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
    
    1. Run apt-get update to add these new repos to the apt-get:
     sudo apt update && sudo apt upgrade
    
    1. To install all key packages
    sudo apt-get install libllvm-15-ocaml-dev libllvm15 llvm-15 llvm-15-dev llvm-15-doc llvm-15-examples llvm-15-runtime
    
    1. Install clang-15
     sudo apt-get install clang-15 lldb-15 lld-15     
    
    1. Make sure now "clang-15" is used by the compiler and not the older "clang" and done just compile your project
    export CMAKE_C_COMPILER=clang-15
    
    export CMAKE_CXX_COMPILER=clang++-15
    

    Doc https://apt.llvm.org/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search