我如何 运行 在 visual studio 代码中调试 c++ 脚本?

How can I run a c++ script in debug in visual studio code?

我必须 运行 在 Visual Studio 代码上调试一个 C++ 脚本,但我做不到。 它告诉我找不到文件 raise.c

无法打开'raise.c':无法读取文件(错误:找不到文件(/build/glibc-B9XfQf/glibc-2.28/sysdeps/unix/sysv/linux/raise.c))。

有什么问题?

晚上好塔诺扎,

问题可能是由于: - 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"
        }
    ]

这是我的 task.json 程序示例,其中包含 opencv 和 python。可能第一个错误是没有引用参数。这个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"
        }
    ]
}

你必须检查这一行 "program": "${fileDirname}/${fileBasenameNoExtension}",

  • 程序代码中
int main(int argc, char* argv[]) 
{
    string folder = argv[1];
}

如果你这样写你会得到错误"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";

这样就没有出现问题了。

我希望这有用,但我不知道这个问题的细节抱歉。