最近我开始使用Bazel,但在调试应用程序时遇到了问题,我可以使用进行调试,但无法调试Bazel生成的.exe文件。
谢谢您的关注。
另外,我使用Bazel和VsCode任务构建源代码。
- 我应该针对哪个.exe文件来调试我的应用程序?
- 我的设置是否正确?
- 在Windows上使用Bazel调试C ++源代码是否可行?
- 我应该使用minGW调试bazel生成的可执行文件还是其他工具或调试器?
版本
- 操作系统:Windows 10
- Bazel版本:Build label: 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;
}
BUILD 文件
cc_binary(
name = "app",
srcs = ["app.cc"]
)
然后我在./CPP_TESTS的根目录下运行以下命令:
bazel build //project/main:app
这个命令将生成一些文件和文件夹。
一些文件夹包含应用程序的 app.exe 文件,例如在 bazel-bin 目录中,我有这些文件和文件夹。|-- 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>
如果我调试应用程序,我会得到这个错误。
在开始之前,这是我的任务/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
}
]
}
]
}
我运行了
bazel build //project/main:app
命令![enter image description here](https://istack.dev59.com/izgmI.gif)
错误信息。
但是 app.exe 在那里呢?![在此输入图片描述](https://istack.dev59.com/fgMT8.webp)