1

I spended around 4 hours today trying to compile C++ code in Visual Studio Code, but I did not even progress by a small bit. There are 2 main issues:

  • #include errors detected.

  • c_cpp_properties.json cannot find "gcc". (That means I cannot compile, or, cannot run the code)

enter image description here

And If I try to use other compilers to compile, It either says that launch program does not exist or provides me other errors.

enter image description here

enter image description here


I already have mingw64 installed (if that matters), and so what should I do? Is it the .json file which is acting up or what? (I will provide all the files just in case there is something wrong in the files.

c_cpp_properties.json

{
  "configurations": [
    {
      "name": "windows-gcc-x64",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "compilerPath": "gcc",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "windows-gcc-x64",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}

settings.json

{
  "C_Cpp_Runner.cCompilerPath": "gcc",
  "C_Cpp_Runner.cppCompilerPath": "g++",
  "C_Cpp_Runner.debuggerPath": "gdb",
  "C_Cpp_Runner.cStandard": "",
  "C_Cpp_Runner.cppStandard": "",
  "C_Cpp_Runner.msvcBatchPath": "",
  "C_Cpp_Runner.useMsvc": false,
  "C_Cpp_Runner.warnings": [
    "-Wall",
    "-Wextra",
    "-Wpedantic"
  ],
  "C_Cpp_Runner.enableWarnings": true,
  "C_Cpp_Runner.warningsAsError": false,
  "C_Cpp_Runner.compilerArgs": [],
  "C_Cpp_Runner.linkerArgs": [],
  "C_Cpp_Runner.includePaths": [],
  "C_Cpp_Runner.includeSearch": [
    "*",
    "**/*"
  ],
  "C_Cpp_Runner.excludeSearch": [
    "**/build",
    "**/build/**",
    "**/.*",
    "**/.*/**",
    "**/.vscode",
    "**/.vscode/**"
  ]
}

launch.json

{
    "configurations": [
        {
            "name": "C/C++ Runner: Debug Session",
            "type": "cppdbg",
            "request": "attach",
            "args": [],
            "stopAtEntry": false,
            "externalConsole": true,
            "cwd": "c:/Users/xyccx_mdrrjg8/Documents/Getting Started",
            "program": "${workspaceRoot}/a.out",
            "MIMode": "gcc",
            "miDebuggerPath": "gcc",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "externalTerminal"
        }
    ],
    "version": "2.0.0"
}
scissors127
  • 21
  • 1
  • 6
  • 2
    Note that Visual Studio and Visual Studio Code are two totally different products. One of them requires a complete configuration with json files https://code.visualstudio.com/docs/setup/windows while the other one comes preconfigured... – BoP Oct 01 '22 at 09:35
  • 1
    Have you grea read the documentation? https://code.visualstudio.com/docs/languages/cpp i concur with the recommendation for visual studio, it's much easier for beginners – Alan Birtles Oct 01 '22 at 09:56
  • 1
    Have you included the path to a compiler, GCC(g++) or whichever, into the environment variable? Even if I could write in VS Code, I moved to Visual Studio community edition, which is much convenient, for my mental peace. And if you need to use unicode text for languages other than English in Windows, using Visual Studio solves the encoding problem. The ways that worked for Windows platform in Visual Studio threw a lot of errors when using GCC in my case. – Smart Humanism Oct 01 '22 at 10:52
  • Possible duplicate of: https://stackoverflow.com/questions/53975157/g-is-not-recognized-as-an-internal-or-external-command-operable-program-or – CPP_is_no_STANDARD Oct 01 '22 at 21:33

0 Answers0