[Solved] How can I run a c++ script in debug in visual studio code? [closed]


Good evening Tanozar,

the problems are probably due to:
– task.json

    "tasks": [
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "`pkg-config", "--cflags", "--libs", "opencv4`",
                "-lcfitsio", "-lcurl",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-lboost_iostreams", "-lboost_system", "-lboost_filesystem", "-lpython2.7", "-lm", "-L/usr/lib/python2.7/config/", "-I/usr/include/python2.7/ ",
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]

this is an example of my task.json for a program that include opencv and python. Probably a first error is that the argument is not quoted. This task.json “correspond to” “g++ -Os -std=c++11 main2.cpp pkg-config --cflags --libs opencv4 -lcfitsio -lcurl -o ~/blabla/main2 -lboost_iostreams -lboost_system -lboost_filesystem -lpython2.7 -lm -L/usr/lib/python2.7/config/ -I/usr/include/python2.7/”

  • launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

you have to check this line “program”: “${fileDirname}/${fileBasenameNoExtension}”,

  • in the program code
int main(int argc, char* argv[]) 
{
    string folder = argv[1];
}

if you write in this way you get the error “Unable to open ‘raise.c’: Unable to read file (Error: File not found (/build/glibc-B9XfQf/glibc-2.28/sysdeps/unix/sysv/linux/raise.c)).”

string folder = "/home/.../pathofyourprogram";

in this way the problem not occured.

I hope that is useful, but i don’t know the detail of this problem sorry.

solved How can I run a c++ script in debug in visual studio code? [closed]