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 1 year has passed since last update.

[macOS] VSCodeでマクロを有効にしてC/C++のソースコードの#ifdefの中をアクティブにする

Last updated at Posted at 2023-10-17

VSCodeのIntelisenseを設定してVSCodeでマクロを有効にする

環境

  • macOS
  • VSCode
    • 拡張機能: C/C++ (Extension Pack)
  • llvm/clang

手順

以下の手順で設定ファイル(c_cpp_properties.json)を開き、編集する。

  • Cmd+Shift+P、C/C++: 構成の編集(JSON)を選択する。
  • definesに有効にしたいマクロを追加する。
    • 例えば、__cplusplusとか。
  • #ifdef内も評価されるようになる。

例(全体):

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",                
            ],
            "defines": [
                "__cplusplus",
            ],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/local/opt/llvm@11/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++11",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

Note

他にも、見た目だけアクティブにするのであればIntellisenseの該当の機能をOffにする方法がある。
こちら

ただ個人的にはIntellisenseにビルドエラーなどを検出して欲しいので適切に環境設定をするのが好み。

参考

0
0
5

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?