味噌汁を飲みます

そんなに深く考えて書いていない twitter: siberiy4

VSCodeでaddrinfo がエラーになる

上の画像のようにaddrinfoの変数にエラーが出る。
実際にはコンパイルできるが、エラーが邪魔である。

github.com

解決方法は、上記issueの通り、

  1. ctrl + shift + P で C/C++ : Edit Configuretions を開く(UI/JSONどちらでもよい)
  2. Definesの項目を見る
  3. 以下のように書き換え
- "defines": [
- ],
+ "defines": [
+      "__linux__",
+     "__x86_64__",
+     "_GNU_SOURCE"
+ ],
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "__linux__",
                "__x86_64__",
                "_GNU_SOURCE"
            ],
            "compilerPath": "/usr/bin/gcc",
            "intelliSenseMode": "linux-gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

UIの場合はこう