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.jsonlike files.
Steps
- Install msys2 https://www.msys2.org/
- Install C++ toolchain
1pacman -Syu2pacman -S mingw-w64-x86_64-gcc3pacman -S mingw-w64-x86_64-cmake # use cmake --build ., no need make4pacman -S mingw-w64-x86_64-clang5pacman -S mingw-w64-x86_64-clang-tools-extra # clangd is here- Find your
clangd.exeinC:\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.02--target=x86_64-w64-windows-gnucheck if a single file can find headers.
(Tested ok)
Use ninja
In msys2:
1pacman -S mingw-w64-x86_64-ninjaWrite cmake as usual. ref: https://blog.51cto.com/u_15127539/3336648
1cd build2# I forget if I need to specify "build for ninja". This just works on my win10 now3cmake ..4ninja installGo to install/bin/ and check generated executable.