参考自:https://www.cnblogs.com/ranjiewen/p/10214728.html,
https://blog.csdn.net/xxmhnu/article/details/80280006
1. 安装vscode
2. 编译darknet
- 将darknet中makefile的CC=gcc改为 CC=gcc -g
参考:https://blog.csdn.net/u011622208/article/details/105025271进行编译
3. vscode项目配置
- vscode默认从系统和${workspaceFolder}(当前打开的文件夹,即darknet目录)下找头文件,所以我们要将工作区的include文件夹加入到配置文件中去。vscode下的C或C++项目的配置文件是c_cpp_properties.json,用快捷键ctrl+shift+p调出vscode命令搜索框,搜索Edit Configurations并点击就会跳转到c_cpp_properties.json文件的编辑界面,将include加入到includePath即可:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include" // 添加了这一句
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "F:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
- task.json文件配置
要启动调试,vscode需要知道编译的可调式的可执行文件的目录,以及带进去的参数,这些内容需要配置到launch.json中。按F5启动调试,选择GDB环境,编辑launch.json如下所示:
共4个需要修改的地方,注释中有编号
{
// 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) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/darknet.exe", // 1.
"args": ["detector", "demo", "cfg/coco.data", "cfg/yolov3.cfg", "models/yolov3.weights", "data/dog.jpg"], // 2
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, // 3
"MIMode": "gdb",
"miDebuggerPath": "F:/cygwin64/bin/gdb.exe", // 4
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
4. 调试项目
在examples/darknet.c的main函数中添加一个断点,然后按F5进行调试。