2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WSL2 vscode で clangd で C++ 補完するメモ(C/C++ for Visual Studio Code を disable が必要)

Last updated at Posted at 2022-11-03

背景

WSL2 で vscode で C++ 補完したくて compile_commands.json 用意したけど認識せぬ... :cry:

VSCode で Windows アプリを Linux 側から cross-compile しているなどで, "C/C++ for Visual Studio Code"(Intellisene 機能だけ?) ではうまく扱えない C/C++ プロジェクトがあることがわかりました.

clangd で補完したいよぉ... 🥺

vscode-clangd 使います.

注意

"C/C++ for Visual Studio Code" と vscode-clangd は共存できません(as of 2022/11/04).
("C/C++ for Visual Studio Code" も中身は clangd 使っているかなとおもったけどちがうっぽ?)

"C/C++ for Visual Studio Code" はとりあえずなんとなく入れている人が多いと思いますのでまずは disable or uninstall しておきます.

image.png

これです.

Intellisense と clangd での補完を切り替えたい場合は... プロジェクトごとに設定切り替えできたりするじゃろか :thinking:)

セットアップ

image.png

clangd(vscode-clangd)を入れます.

あとは cmake などで compile_commands.json を作っておき, プロジェクトの直下か,
.vscode/c_cpp_settings.jsoncompile_commands.json のパスを通します!

ありがとうございます.

動作確認

WSL(Linux)で, clang-cl でクロスコンパイルするような構成です. compile_commands.json は

{"directory": "/home/syoyo/work/tinyusdz/build-clang-cl-wsl",
 "command": "/home/syoyo/local/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-cl  /nologo -TP -DTINYUSDZ_USE_USDOBJ -DTINYUSDZ_USE_USDVOX -DTINYUSDZ_WITH_AUDIO -DTINYUSDZ_WITH_COLORIO -DTINYUSDZ_WITH_EXR -I/home/syoyo/work/tinyusdz/src  -D_CRT_SECURE_NO_WARNINGS --target=x86_64-windows-msvc -fms-compa  tibility-version=19.11 -imsvc \"/mnt/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/atlmfc/include\" -imsvc \"/mnt/c/  Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/include\" -imsvc \"/mnt/c/Program Files (x86)/Windows Kits/10/Include/10  .0.19041.0/ucrt\" -imsvc \"/mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -imsvc \"/mnt/c/Program Files (x86)/Windows Kits/10/Inclu  de/10.0.19041.0/um\" -imsvc \"/mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" /Zi /Ob0 /Od /RTC1 -MDd -std:c++14 -Weverything -Werror   -Wno-padded -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-documentation -Wno-unused-member-function /FoCMakeFiles/tinyusdz_static.dir/src/asset-resoluti  on.cc.obj /FdTARGET_COMPILE_PDB -c -- /home/syoyo/work/tinyusdz/src/asset-resolution.cc",
"file": "/home/syoyo/work/tinyusdz/src/asset-resolution.cc"
}, 

こんな感じのです.

image.png

こんな感じで _MSC_VER 認識したり, Windows.h へジャンプできました!(WSL の Linux 側から)

TODO

  • task.json から compile_commands.json でのビルドをする方法を調べる(もしくは cmake configure の構成を手動指定して, compile_commands.json を VSCode の CMake extension から生成するようにする方法をしらべる)
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?