简体   繁体   中英

Trying to debug c++ through vscode

Im studying c++ and im having a big problem debugging in vscode since everytime i try to debug i get this error The preLaunchTask 'C/C++':g++.exe build active file' terminated with exit code -1 I never have problems with compiling it but the debugger seems to be useless. whenever i print though like one simple task such as cout << "hello"<<endl; the debugger seems to work.

after this display i click on the button "debug anyway" and it tells me launch: program 'c:\Users...\main.exe' does not exist. this is my launch.json file:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "g++.exe - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "C/C++: g++.exe build active file"
    }
]
}

I'm so desperate about it i've been trying to sort it out for days now. (checking on other articles in stackoverflow, reinstalling vscode etc.)

https://code.visualstudio.com/docs/editor/debugging

  • preLaunchTask - to launch a task before the start of a debug session, set this attribute to the label of a task specified in tasks.json (in the workspace's.vscode folder). Or, this can be set to ${defaultBuildTask} to use your default build task.

We can't see your tasks.json file but my suggestion is to set the value in preLaunchTask to ${defaultBuildTask}.

The documentation on Visual Studio Code is pretty good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM