Difference between revisions of "CB Clangd Client"

From Code::Blocks
Line 5: Line 5:
 
The related forum discussion is:  — [https://forums.codeblocks.org/index.php/topic,24357.html Code completion using LSP and clangd]
 
The related forum discussion is:  — [https://forums.codeblocks.org/index.php/topic,24357.html Code completion using LSP and clangd]
  
Windows Clangd executable install process:
+
 
==========================================
+
'''Windows Clangd executable install process:'''
  
 
There are three main options to install the clangd.exe:
 
There are three main options to install the clangd.exe:
1) Install the LLVM compiler.
+
 
2) Manully extract the required files from the LLVM compiler.
+
    1) Install the LLVM compiler.
3) Install the Clangd package for the Windows compiler you are using if it is available.
+
    2) Manully extract the required files from the LLVM compiler.
 +
    3) Install the Clangd package for the Windows compiler you are using if it is available.
  
 
The  process for the three options above are detailed below.
 
The  process for the three options above are detailed below.
  
Install the LLVM compiler
+
 
=========================
+
'''Install the LLVM compiler'''
1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following Github LLVM download page:
+
 
      https://github.com/llvm/llvm-project/releases
+
    1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following  
 +
      Github LLVM download page:
 +
      https://github.com/llvm/llvm-project/releases
  
 
   As of Jan 2022 the Windows files are names as follows:
 
   As of Jan 2022 the Windows files are names as follows:
Line 25: Line 28:
 
   where <version> is the LLVM version, like 13.0.0 or 13.0.1.
 
   where <version> is the LLVM version, like 13.0.0 or 13.0.1.
  
2) Run the LLVM-<version>-win<xx>.exe you downlaoded to install the LLVM compiler.
+
    2) Run the LLVM-<version>-win<xx>.exe you downlaoded to install the LLVM compiler.
  
  
  
Manually Extract File from LLVM compiler
+
'''Manually Extract File from LLVM compiler'''
=========================================
+
    1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following  
1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following Github LLVM download page:
+
      Github LLVM download page:
      https://github.com/llvm/llvm-project/releases
+
      https://github.com/llvm/llvm-project/releases
  
 
   As of Jan 2022 the Windows files are names as follows:
 
   As of Jan 2022 the Windows files are names as follows:
Line 38: Line 41:
 
       LLVM-<version>-win32.exe
 
       LLVM-<version>-win32.exe
 
   where <version> is the LLVM version, like 13.0.0 or 13.0.1.
 
   where <version> is the LLVM version, like 13.0.0 or 13.0.1.
2) Unzip the LLVM-<version>-win<xx>.exe file you downloaded using 7ZIP or your prefered ZIP program into a sub directory
+
 
3) Create a new directory to put the clangd.exe and dll's
+
    2) Unzip the LLVM-<version>-win<xx>.exe file you downloaded using 7ZIP or your prefered ZIP program into a sub  
4) Copy the following files into a the new directory created from the unziped LLVM directory:
+
      directory
 +
    3) Create a new directory to put the clangd.exe and dll's
 +
    4) Copy the following files into a the new directory created from the unziped LLVM directory:
 
             bin\clangd.exe
 
             bin\clangd.exe
 
             bin\msvcp140.dll
 
             bin\msvcp140.dll
Line 48: Line 53:
  
  
Windows Compiler Clangd/LLVM Pacakage Installer
+
'''Windows Compiler Clangd/LLVM Pacakage Installer'''
===============================================
+
    Due to the number of different compilers available for Windows not all of the compilers will have either/both  
Due to the number of different compilers available for Windows not all of the compilers will have either/both the Clang or LLVM required files.
+
    the Clang or LLVM required files.
  
If you want to install the specific package(s) for the Windows compiler you are using in order to use it's clangd.exe file please follow the  
+
    If you want to install the specific package(s) for the Windows compiler you are using in order to use it's  
instructions below for the specific compiler you have installed:
+
    clangd.exe file please follow the  
 +
    instructions below for the specific compiler you have installed:
  
MSYS2 Compiler - MinGW64
+
'''MSYS2 Compiler - MinGW64'''
-------------------------
 
 
There are two main options to install the clangd.exe as follows:
 
There are two main options to install the clangd.exe as follows:
     1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the following packages:
+
     1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the  
 +
        following packages:
 
         +------------------------------------------+------------------------+
 
         +------------------------------------------+------------------------+
 
         |              Package                    | Clangd executable      |
 
         |              Package                    | Clangd executable      |
Line 71: Line 77:
 
               pacman -S <Package name in the table above>
 
               pacman -S <Package name in the table above>
 
      
 
      
OR
+
    '''OR'''
 
     2) The second option is to intall the full Clang tool chain as follows:
 
     2) The second option is to intall the full Clang tool chain as follows:
 
         a)  Open the msys2.exe bash shell  
 
         a)  Open the msys2.exe bash shell  
Line 77: Line 83:
 
               pacman -S mingw-w64-clang-x86_64-toolchain
 
               pacman -S mingw-w64-clang-x86_64-toolchain
  
 +
'''MSYS2 Compiler - MinGW32'''
 +
    There are two main options to install the clangd.exe as follows:
  
 
+
     1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the  
 
+
      following packages:
-------------------------
 
MSYS2 Compiler - MinGW32
 
There are two main options to install the clangd.exe as follows:
 
     1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the following packages:
 
 
         +------------------------------------------+------------------------+
 
         +------------------------------------------+------------------------+
 
         |              Package                    | Clangd executable      |
 
         |              Package                    | Clangd executable      |
Line 95: Line 99:
 
         b) Run the following command:
 
         b) Run the following command:
 
               pacman -S <Package name in the table above>
 
               pacman -S <Package name in the table above>
   
+
    '''OR'''
OR
+
 
 
     2) The second option is to intall the full Clang tool chain as follows:
 
     2) The second option is to intall the full Clang tool chain as follows:
 
         a)  Open the msys2.exe bash shell  
 
         a)  Open the msys2.exe bash shell  
Line 113: Line 117:
 
you should use "mingw-w64-clang-x86_64-clang-tools-extra".
 
you should use "mingw-w64-clang-x86_64-clang-tools-extra".
  
I found that I just make a big mistake in one of my PC, that is I use the gcc toolchain from "msys64\mingw64\bin",  
+
I found that I just make a big mistake in one of my PC, that is I use the gcc toolchain from  
but I use the clangd.exe from "msys64\clang64\bin", the result is I got a lot of LSP diagnostics messages about  
+
        "msys64\mingw64\bin",  
the errors.  ;)  Luckily I found the reason, and fix this issue. Hope this will help other guys.
+
but I use the clangd.exe from "msys64\clang64\bin", the result is I got a lot of LSP diagnostics messages  
 +
        about the errors.  ;)   
 +
        Luckily I found the reason, and fix this issue. Hope this will help other guys.

Revision as of 18:10, 2 November 2022

The repository page of this plugin is: https://sourceforge.net/projects/cb-clangd-client/

It uses clangd through Language Server Protocol.

The related forum discussion is: — Code completion using LSP and clangd


Windows Clangd executable install process:

There are three main options to install the clangd.exe:

   1) Install the LLVM compiler.
   2) Manully extract the required files from the LLVM compiler.
   3) Install the Clangd package for the Windows compiler you are using if it is available.

The process for the three options above are detailed below.


Install the LLVM compiler

   1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following 
      Github LLVM download page:
      https://github.com/llvm/llvm-project/releases
  As of Jan 2022 the Windows files are names as follows:
     LLVM-<version>-win64.exe
     LLVM-<version>-win32.exe
  where <version> is the LLVM version, like 13.0.0 or 13.0.1.
   2) Run the LLVM-<version>-win<xx>.exe you downlaoded to install the LLVM compiler.


Manually Extract File from LLVM compiler

   1) Download the latest (non RC/Beta)LLVM Windows executable for your OS (Win32 or Win64) from the following 
      Github LLVM download page:
      https://github.com/llvm/llvm-project/releases
  As of Jan 2022 the Windows files are names as follows:
     LLVM-<version>-win64.exe
     LLVM-<version>-win32.exe
  where <version> is the LLVM version, like 13.0.0 or 13.0.1.
   2) Unzip the LLVM-<version>-win<xx>.exe file you downloaded using 7ZIP or your prefered ZIP program into a sub 
      directory
   3) Create a new directory to put the clangd.exe and dll's
   4) Copy the following files into a the new directory created from the unziped LLVM directory:
           bin\clangd.exe
           bin\msvcp140.dll
           bin\vcruntime140.dll
           bin\vcruntime140_1.dll


Windows Compiler Clangd/LLVM Pacakage Installer

   Due to the number of different compilers available for Windows not all of the compilers will have either/both 
   the Clang or LLVM required files.
   If you want to install the specific package(s) for the Windows compiler you are using in order to use it's 
   clangd.exe file please follow the 
   instructions below for the specific compiler you have installed:

MSYS2 Compiler - MinGW64 There are two main options to install the clangd.exe as follows:

   1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the 
       following packages:
       +------------------------------------------+------------------------+
       |               Package                    | Clangd executable      |
       +------------------------------------------+------------------------+
       | mingw-w64-clang-x86_64-clang-tools-extra | clang64/bin/clangd.exe |
       | mingw-w64-x86_64-clang-tools-extra       | mingw64/bin/clangd.exe |
       +------------------------------------------+------------------------+
      To intall the package do the following:
       a)  Open the msys2.exe bash shell 
       b) Run the following command:
              pacman -S <Package name in the table above>
   
   OR
   2) The second option is to intall the full Clang tool chain as follows:
       a)  Open the msys2.exe bash shell 
       b) Run the following command:
              pacman -S mingw-w64-clang-x86_64-toolchain

MSYS2 Compiler - MinGW32

   There are two main options to install the clangd.exe as follows:
   1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the 
      following packages:
       +------------------------------------------+------------------------+
       |               Package                    | Clangd executable      |
       +------------------------------------------+------------------------+
       | mingw-w64-clang-i686-clang-tools-extra   | clang32/bin/clangd.exe |
       | mingw-w64-i686-clang-tools-extra         | mingw32/bin/clangd.exe |
       +------------------------------------------+------------------------+
      To intall the package do the following:
       a)  Open the msys2.exe bash shell 
       b) Run the following command:
              pacman -S <Package name in the table above>
    OR
   2) The second option is to intall the full Clang tool chain as follows:
       a)  Open the msys2.exe bash shell 
       b) Run the following command:
              pacman -S mingw-w64-clang-i686-toolchain

Notes from the CodeBlocks forum to avoid mixing incompatible gcc/clangd executables.


https://forums.codeblocks.org/index.php/topic,24357.msg169412.html#msg169412 If you are using the gcc from msys2, I mean the compilers in the folder "msys64\mingw64\bin", you should use "mingw-w64-x86_64-clang-tools-extra", which means the clangd.exe is under the folder "msys64\mingw64\bin" (the same folder in your gcc.exe).

If you are using the clang tool chain, I mean you use the compiler from the folder "msys64\clang64\bin", you should use "mingw-w64-clang-x86_64-clang-tools-extra".

I found that I just make a big mistake in one of my PC, that is I use the gcc toolchain from

       "msys64\mingw64\bin", 

but I use the clangd.exe from "msys64\clang64\bin", the result is I got a lot of LSP diagnostics messages

       about the errors.  ;)   
       Luckily I found the reason, and fix this issue. Hope this will help other guys.