0
0

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.

VSCodeでクロス開発してるときに出るIntelliSenseのエラーをなんとかしたい

Posted at

エラーの原因

VSCode でマイコンなどのコードを書いていると、既存のライブラリのincludeでIntelliSenseがエラーを出すことがあります。includePath が正しいにもかかわらず、です。

たとえば以下のようなヘッダファイルが問題になります。

# ifdef __APPLE__
# include <DefinitionsForMac.h>  // ./configure で動的に生成されるファイルで、存在しない
# endif

gcc や clang は暗黙的にいくつかのマクロを定義します。この __APPLE__ もその一つです。
そして IntelliSense は「VSCode を動かしているホストPCでコンパイルする」と想定して、これらのマクロを定義した状態でコードをスキャンします。

でもクロスビルド用のgccではそんなマクロは定義しないので、make の実行ではエラーになりません。
(compilerPath でちゃんとcross-gccを指定してるんだからそっち見てよという気持ちがなきにしもあらず)

Workaround

以下のようにホストコンパイラの暗黙的マクロをundefしたヘッダファイルを作ります。

echo | clang -dM -E - | sed "s/^#define/#undef/" > .vscode/cross.h
echo | cross-gcc -dM -E - >> .vscode/cross.h

でもってc_cpp_properties.jsonforcedIncludeに指定します。

"forcedInclude": [ "${workspaceFolder}/.vscode/cross.h" ],

VSCode 本体の修正

それなりに困っている人もいるようで、https://github.com/microsoft/vscode-cpptools/issues/1083 で議論されています。そのうち修正されるといいな。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?