如何使用vscode调试包含多个makefile的c++项目
时间: 2023-12-13 11:05:38 浏览: 88
在使用VSCode调试包含多个Makefile的C++项目之前,需要先确保已安装以下工具:
1. C/C++插件
2. Make工具
3. GDB调试器
接下来,按照以下步骤进行操作:
1. 打开C++项目所在的文件夹,按下F5或者点击左侧调试栏中的“启动调试”按钮。
2. 在弹出的“选择环境”窗口中,选择“C++ (GDB/LLDB)”环境,然后点击“创建配置文件”。
3. 在打开的“launch.json”文件中,添加以下配置:
```
{
"name": "Debug Multi Makefile Project",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/path/to/executable",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set breakpoint at main",
"text": "break main",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
```
其中,需要将“program”字段的值设置为项目生成的可执行文件的路径,将“miDebuggerPath”字段的值设置为GDB调试器的路径,将“setupCommands”字段中的“text”值设置为需要执行的GDB命令,比如“break main”可以在程序开始执行时自动停在main函数处。
4. 在VSCode中打开项目的“tasks.json”文件,在该文件中配置需要执行的Makefile命令,比如:
```
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make -f makefile1 && make -f makefile2",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
```
其中,“command”字段的值为需要执行的Makefile命令,可以包括多个Makefile。
5. 按下F5或者点击左侧调试栏中的“启动调试”按钮,等待程序运行到设置的断点处即可开始调试。
希望这些步骤能够对你有所帮助。
相关推荐
![json](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)