繁体   English   中英

如何在大型 C++ 项目的可视化代码中设置调试

[英]How do I set up debugging in visual code for a large c++ project

我是 c++ 和 vs-code 的初学者,但我的任务是使用/开发现有的 c++ 项目(在此之前我使用过 python 和 sublime)。

我希望能够配置 vs 代码,以便我可以轻松地调试和编译代码而不会太麻烦。

目前,这是我这样做的方式:

  • 对代码进行一些更改,例如在 $basedir/src/folder1/file.cpp 中
  • 转到终端中的 $basedir,然后运行
  • a) 制作
  • b)等待它通过一堆文件夹找到已更改的文件。
  • c) cd $basedir/programs/dawn; 打扫干净; 制作
  • 最后运行一个类型的项目: $basedir/programs/project/projectname inputfile.json

我想要做的就是按 F5(用于调试,或按 ctrl+F5 运行),但我不知道如何设置所有东西都是 vs 代码。 有人能帮我吗?

这些是我的配置文件:在 c_cpp_properties.json 中,我引用了另外两个项目,但我还必须添加当前项目的包含目录,以便 vs-code 不会抱怨包含文件等(我认为它会自动使用${workspaceFolder}/**在项目中查找文件)

{
"configurations": [
    {
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}/**",
            "~/otherproject1/include/",
            "~/otherproject2/include/",
            "~/Documents/projectname/include"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
],
"version": 4
}

{

任务文件

"tasks": [
    {
        "type": "shell",
        "label": "g++ build active file",
        "command": "/usr/bin/g++",
        "args": [
            "cd ${workspaceFolder};",
            "make;",
            "make clean -C programs/projectname;",
            "make -C programs/projectname;",
        ],
        "options": {
            "cwd": "/usr/bin"
        }
    }
],
"version": "2.0.0"
}

启动文件

{
// 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++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/programs/projectname inputfile.json",
        "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"
    }
]
}

Microsoft 为设置调试环境提供了很好的教程。

请查看这些教程:

VSCode CPP 调试

配置 mingW 和 GCC 调试

您的配置中很明显的是您在这里错过了.exe

"program": "${fileDirname}/${fileBasenameNoExtension}", //< -- wrong
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // < -- correct

并找到您的调试器并在此处添加路径:

"miDebuggerPath": "C:\\path\\to\\gdb.exe",

要开始调试只需点击F5 对于构建,按CTRL + SHIFT + B并选择您的构建任务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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