中国建设网站银行,苏州建设网站微信公众号,做网站的思路怎么写,牡丹江生活信息网Linux环境使用VSCode调试简单C代码_linux vscode编译c代码_果壳中的robot的博客-CSDN博客
Linux环境下使用VScode调试CMake工程 - 知乎
1 vscode实现cmakemake指令
我们都知道#xff0c;对于cmake构建的工程#xff0c;编译需要以下步骤:
cd build
cmake ..
make
那如… Linux环境使用VSCode调试简单C代码_linux vscode编译c代码_果壳中的robot的博客-CSDN博客
Linux环境下使用VScode调试CMake工程 - 知乎
1 vscode实现cmakemake指令
我们都知道对于cmake构建的工程编译需要以下步骤:
cd build
cmake ..
make
那如何让vscode来帮我们执行呢答案就是构建下面的task.json文件。构建步骤为 * 在VSCode的主菜单中选择 TerminalConfigure Default Build Task * 选择 CMake: build * 将生成一个 tasks.json文件将其中的内容作相应的替换 可以看出上面的 tasks.json 文件主要包含三个命令 label为cmake的任务执行shell类型的cmake命令其参数为 ../执行时所在的目录为${fileDirname}/build。这个命令等价于在build目录下执行cmake ../label为make的任务执行shell类型的make命令没有参数执行时所在的目录为${fileDirname}/build。这个命令等价于在build目录下执行makelabel为build的任务该任务由cmake和make任务组成也就是将上面两条命令执行的过程组合成一个build任务。 // tasks.json
{version: 2.0.0,tasks: [{label: cmake,type: shell,command: cmake,args: [..],options: {cwd: ${workspaceFolder}/yolov8/build}, },{label: make,type: shell,command: make,args: [],options: {cwd: ${workspaceFolder}/yolov8/build}, },{label: build,// 依赖于上述的两个 label为 cmake和 make的任务dependsOn:[cmake, make]},],
}
2 vscode实现debug run
我们都知道对于cmake构建的工程编译需要以下步骤: 1. 在VSCode的上方菜单中选择 Run - Add Configuration会生成一个空白的launch.json文件 2. 我们要做的就是在该文件中告诉VSCode用gdb调试前面生成的可执行文件在launch.json文件中添加如下内容 launch.json
//json.sh
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid830387version: 0.2.0,configurations: [{name: (gdb) Launch,type: cppdbg,request: launch,program: ${workspaceFolder}/yolov8/build/app_yolov8,args: [ ],stopAtEntry: true,cwd: ${workspaceFolder}/yolov8/build,environment: [],externalConsole: false,MIMode: gdb,setupCommands: [{description: Enable pretty-printing for gdb,text: -enable-pretty-printing,ignoreFailures: true},{description: Set Disassembly Flavor to Intel,text: -gdb-set disassembly-flavor intel,ignoreFailures: true}],preLaunchTask: build,miDebuggerPath: /usr/bin/gdb}]
} 其中 program用于指定要调试的可执行文件这里用变量名指代其值就是helloCMakeargs执行代码时需要添加的命令行参数prelaunchTask在执行gdb调试前预先需要执行的任务这里设置为build就是指定上一节中配置完成的build任务即在gdb调试前先执行cmake和make 打上断点然后按F5即可实现代码调试