Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何调试c++;在Windows 10操作系统上使用Bazel编写代码_C++_Debugging_Visual Studio Code_Bazel_Vscode Tasks - Fatal编程技术网

C++ 如何调试c++;在Windows 10操作系统上使用Bazel编写代码

C++ 如何调试c++;在Windows 10操作系统上使用Bazel编写代码,c++,debugging,visual-studio-code,bazel,vscode-tasks,C++,Debugging,Visual Studio Code,Bazel,Vscode Tasks,最近我开始玩Bazel,我在调试应用程序时遇到了一个问题,我可以用g++进行调试,但无法调试Bazel生成的.exe文件 谢谢你看这个 此外,我还使用Bazel和VsCode任务构建源代码 我应该以哪个.exe文件为目标来调试我的应用程序 我的设置好了吗 可以在Windows .b/LI>上使用BAZEL调试C++源代码。 我应该在bazel生成的可执行文件或其他文件中使用minGW进行调试吗 其他工具或调试器 版本 操作系统:Windows 10 Bazel版本:生成标签:0.20.0 我

最近我开始玩Bazel,我在调试应用程序时遇到了一个问题,我可以用g++进行调试,但无法调试Bazel生成的.exe文件

谢谢你看这个

此外,我还使用Bazel和VsCode任务构建源代码

  • 我应该以哪个.exe文件为目标来调试我的应用程序
  • 我的设置好了吗
  • 可以在Windows .b/LI>上使用BAZEL调试C++源代码。
  • 我应该在bazel生成的可执行文件或其他文件中使用minGW进行调试吗 其他工具或调试器
  • 版本

    • 操作系统:Windows 10
    • Bazel版本:生成标签:0.20.0
    我有这个项目结构: 然后我在./CPP\u测试的根上运行这个命令

    bazel build//project/main:app

    此命令将生成一些文件和文件夹

    某些文件夹包含app.exe文件,例如在 bazel bindir我有这个文件和文件夹

    |-- bazel-bin
        |-- project
        |   |-- main
        |       |-- app.exe
        |       |-- app.exe-2.params
        |       |-- app.exe.runfiles_manifest
        |       |-- app.pdb
        |       |-- app.exe.runfiles
        |       |   |-- MANIFEST
        |       |-- _objs
        |           |-- app
        |               |-- app.obj
        |-- project-name
            |-- main
                |-- app.exe
                |-- app.exe-2.params
                |-- app.exe.runfiles_manifest
                |-- app.pdb
                |-- app.exe.runfiles
                |   |-- MANIFEST
                |-- _objs
                    |-- app
                        |-- app.obj
    
    所以如果我在

    如果我调试应用程序,就会出现此错误

    在开始之前,这是我的任务/json

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "bazel_run",
                "type": "shell",
                "command": "bazel run //project/main:app",
                "args": [],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            },
            {
                "label": "bazel_build",
                "type": "shell",
                "command": "bazel build //project/main:app",
                "args": [],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            },
            {
                "label": "bazel_debug_build",
                "type": "shell",
                "command": "bazel",
                "args": [
                    "build",
                    "//project/main:app",
                    "--compilation_mode=dbg"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "problemMatcher": [
                    "$gcc"
                ]
            }
        ]
    }
    
    launch.json 因此,我运行了
    bazel build//project/main:app
    命令

    错误消息。

    但是app.exe在那里吗?
    请参阅我对相关问题的回答:

    虽然我无法判断您的设置是否正确(我需要了解更多信息,例如您安装了什么VSCode插件,其他.json文件的内容是什么),但我可以肯定地说,您有两个
    WORKSPACE
    文件看起来是错的


    您应该删除
    project\WORKSPACE
    ,因为Bazel认为每个带有
    WORKSPACE
    文件的目录树都是唯一的工作空间。每个工作区在其根目录中只需要一个工作区文件。如果子目录有自己的工作区文件,那么它是一个单独的工作区,Bazel不会在“父”工作区中使用其中的目标。

    您应该使用位于生成文件夹
    Bazel out/x64\u windows-dbg/project/main/app.exe
    中的可执行文件

    如果要设置断点,可能还需要
    --strip=never
    参数


    如果不起作用,请在launch.json中尝试使用“cppvsdbg”而不是“cppdbg”作为配置类型。

    首先,您需要添加一些bazel选项进行调试。手册在这里:

    如果要调试程序,则需要以下选项:

    bazel build --copt="-g" --strip="never" ... 
    

    嘿,如果你换了C++标签的一个标签,你可能会得到更多的视图。人们倾向于看这个,而不是c++17标签。
    |-- bazel-bin
        |-- project
        |   |-- main
        |       |-- app.exe
        |       |-- app.exe-2.params
        |       |-- app.exe.runfiles_manifest
        |       |-- app.pdb
        |       |-- app.exe.runfiles
        |       |   |-- MANIFEST
        |       |-- _objs
        |           |-- app
        |               |-- app.obj
        |-- project-name
            |-- main
                |-- app.exe
                |-- app.exe-2.params
                |-- app.exe.runfiles_manifest
                |-- app.pdb
                |-- app.exe.runfiles
                |   |-- MANIFEST
                |-- _objs
                    |-- app
                        |-- app.obj
    
    |-- bazel-bin
        |-- project
        |   |-- main
        |       |-- app.exe   <=========
    
    INFO: Elapsed time: 0,145s, Critical Path: 0,01s
    INFO: 0 processes.
    INFO: Build completed successfully, 1 total action
    INFO: Build completed successfully, 1 total action
    Hello world
    8
    PS C:\dev\tests\cpp_tests>
    
    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "bazel_run",
                "type": "shell",
                "command": "bazel run //project/main:app",
                "args": [],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            },
            {
                "label": "bazel_build",
                "type": "shell",
                "command": "bazel build //project/main:app",
                "args": [],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            },
            {
                "label": "bazel_debug_build",
                "type": "shell",
                "command": "bazel",
                "args": [
                    "build",
                    "//project/main:app",
                    "--compilation_mode=dbg"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "problemMatcher": [
                    "$gcc"
                ]
            }
        ]
    }
    
    {
        // 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": "(gdb) Launch",
                "type": "cppdbg",
                "request": "launch",
                // "program": "${workspaceFolder}/a.exe",
                "program": "${workspaceFolder}\\bazel-bin\\project\\main\\app.exe",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": true,
                "MIMode": "gdb",
                "miDebuggerPath": "C:/MinGW/bin/gdb.exe",
                "preLaunchTask": "bazel_debug_build",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    
    bazel build --copt="-g" --strip="never" ...