1
2

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 3 years have passed since last update.

bearとcompdbでC/C++のヘッダファイル込みのcompile_commands.jsonを吐く

Posted at

Bearについて

cmakeとか使ってないC/C++のプロジェクトでもclangdとかのlanguage serverのためにcompile_commands.jsonがほしいとき

$ bear -- make

みたいにすることでcompile_commands.jsonを勝手に吐いてくれるすごいやつがbear。

--は比較的新しいバージョンで必要になった気がする)

GitHub: rizsotto/Bear

しかしヘッダファイルまで含めてくれないので、ヘッダーを編集してる時にlspの補完とかエラーチェックが効かなくて困ることがしばしば。

上のIssueによればcompdbなるものを併用すれば良いとのこと。

compdbのインストール

GitHub: Sarcasm/compdb

インストール:

$ pip install compdb

バージョンの表示:

$ compdb version
compdb version 0.2.0

使い方

Makefileが置いてあるディレクトリにて

$ bear -- make
$ compdb list | sponge compile_commands.json

compdbcompile_commands.jsonを読み込んで新しいcompile_commands.jsonを吐く。

以下のようにやるとcompile_commands.jsonが読み込まれている間にリダイレクトで書き込まれて壊れてしまうのでmoreutilsspongeコマンドを使っている。この辺は適当に。

$ compdb list > compile_commands.json

-p BUILD_DIRでbuildディレクトリを指定することも可能)

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?