【发布时间】:2019-05-18 04:18:34
【问题描述】:
最近我开始玩 Bazel,但在调试应用程序时遇到问题,我可以使用 g++ 进行调试,但无法调试生成的 Bazel 。 exe文件。
感谢您观看此内容。
另外,我使用 Bazel 和 VsCode 任务构建源代码。
- 我应该以哪个 .exe 文件为目标来调试我的应用程序?
- 我的设置好吗?
- 可以在 Windows 上使用 Bazel 调试 c++ 源代码。?
- 我应该使用 minGW 来调试 bazel 生成的可执行文件还是一些 其他工具或调试器。?
版本
- 操作系统:Windows 10
- Bazel 版本:构建标签:0.20.0
我有这个项目结构:
|-- CPP_TESTS
|-- .gitignore
|-- a.exe <-- I generated this with g++ minGW
|-- readme.md
|-- WORKSPACE
|-- .vscode
| |-- c_cpp_properties.json
| |-- launch.json
| |-- settings.json
| |-- tasks.json
|-- project
|-- WORKSPACE
|-- main
|-- app.cc
|-- BUILD
|-- readme.md
app.cc
#include <iostream>
int main(int argc, char const *argv[])
{
int a = 3;
int b = 5;
int c = a + b;
/* code */
std::cout << "Hello world" << std::endl;
std::cout << c << std::endl;
return 0;
}
构建文件
cc_binary(
name = "app",
srcs = ["app.cc"]
)
然后我在 ./CPP_TESTS 的根目录上运行此命令
bazel build //project/main:app
这个命令会生成一些文件和文件夹
某些文件夹包含 app.exe 文件,例如在 bazel-bin dir 我有这个文件和文件夹
|-- 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
所以如果我在
里面运行app.exe
|-- 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>
如果我调试应用程序,我会收到此错误。
在我开始之前,这是我的 tasks/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
{
// 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
}
]
}
]
}
错误信息。
【问题讨论】:
-
嘿,如果您将其中一个标签换成 c++ 标签,您可能会获得更多浏览量。人们倾向于看那个,而不是 c++17 标签。
标签: c++ debugging visual-studio-code bazel vscode-tasks