how to

Setup clangd, cmake just like on unix

Jul 3, 2024
softwares-and-toolsvscodewindows
1 Minutes
141 Words

Setup clangd, cmake just like on unix

ref: https://blog.csdn.net/tyKuGengty/article/details/120119820 (not reliable) ref: https://www.perplexity.ai/search/windows-shang-ru-he-huo-qu-he-UAy020tWRWG50tRSmDYuIw#0

Don’t

  • Don’t use clangd exe downloaded by clangd extension in vscode.
  • Don’t need tasks.json like files.

Steps

1
pacman -Syu
2
pacman -S mingw-w64-x86_64-gcc
3
pacman -S mingw-w64-x86_64-cmake # use cmake --build ., no need make
4
pacman -S mingw-w64-x86_64-clang
5
pacman -S mingw-w64-x86_64-clang-tools-extra # clangd is here
  • Find your clangd.exe in C:\msys64\mingw64\clangd.exe
  • Put the path in your vscode clangd settings.

Done.

Test

  • Create unix like cmake project
  • cd build
  • cmake ..
  • Reload vscode window and see if it can find headers

If you want lsp without cmake

Add this two flags to your vscode clangd fallback flags:

1
-IC:/msys64/mingw64/include/c++/14.1.0
2
--target=x86_64-w64-windows-gnu

check if a single file can find headers.

(Tested ok)

Use ninja

In msys2:

1
pacman -S mingw-w64-x86_64-ninja

Write cmake as usual. ref: https://blog.51cto.com/u_15127539/3336648

1
cd build
2
# I forget if I need to specify "build for ninja". This just works on my win10 now
3
cmake ..
4
ninja install

Go to install/bin/ and check generated executable.

Article title:Setup clangd, cmake just like on unix
Article author:Julyfun
Release time:Jul 3, 2024
Copyright 2025
Sitemap