rtx_q505
rtx_q505

Reputation: 11

Error during build of cpp file in VSC: "Errors exist after running preLaunchTask 'C/C++:cpp.exe build active file"

I am unable to run my code and execute the build of the .exe file in the cpp language in Visual Studio Code.

I have downloaded and installed GCC, MinGW software, MinGW-w64 GCC, etc. according to the instructions here and have successfully verified that gcc g++ and gdb are all installed (by checking 'gcc --version' etc in the commad prompt). My intent is to use this compiler to compile my code but it seems I cannot find the correct compiler under the options listed here to simply 'build and debug the active file'.

I also (and perhaps consequentially) have run into a problem with launch.json not being able to build the executable file.

Can someone please help me with this? This is incredibly frustrating and I simply want to be able to run my code. I downloaded MinGW along with gcc is a good compiler for this very purpose.

Image of error message 1: here, to which I click 'debug anyway' and get the next error: Image of error message 2: here.

Image of launch.json with the configuration that I thought would be appropriate (I found this from another source online): here.

Thank you!!

Upvotes: 1

Views: 3260

Answers (1)

Rohan Bari
Rohan Bari

Reputation: 7726

I recommend deleting all the configurations under the .vscode directory, as they can be regenerated again. After deletion, follow the steps:

  1. Go to your program file, and press F5 to launch debug.

    Debugging settings

  2. Select g++.exe build and debug active file or a convenient option.

    g++.exe build and debug active file

  3. A tasks.json under the .vscode will be generated with the appropriate instructions and the program will be executed instantly.

    Working debugger

    For example, in my case, it was this:

    {
        "tasks": [
            {
                "type": "cppbuild",
                "label": "C/C++: g++.exe build active file",
                "command": "C:\\TDM-GCC-64\\bin\\g++.exe",
                "args": [ // ----- given by me in C/C++ extension settings
                    "-fdiagnostics-color=always",
                    "-Wall",
                    "-O3",
                    "-pedantic",
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}\\${fileBasenameNoExtension}.exe"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": ["$gcc"],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "Task generated by Debugger."
            }
        ],
        "version": "2.0.0"
    }
    

Upvotes: 2

Related Questions