本帖最后由 qinyunti 于 2023-10-27 14:05 编辑
一.前言
前面我们搭建了libusb的开发环境进行编译和调试,但是都是基于命令行的方式,不是很方便。这一篇我们来介绍基于vscode的开发环境搭建。
二.安装vscode
sudo apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=arm64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt install code
此时看到安装的vscode,但是还不能直接打开
需要按如下设置
输入code查找到vscode,右键点击Edit
修改命令行为/usr/share/code/code --no-sandbox --unity-launch %F,点击save
此时就可以打开vscode了
开始需要设置一个密码
三.Vscode使用
3.1打开文件夹
3.2编译配置
创建.vscode文件夹,下面创建tasks.json文件
输入以下内容
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "gcc libusb/*.c libusb/os/events_posix.c libusb/os/linux_udev.c libusb/os/linux_usbfs.c libusb/os/threads_posix.c ./examples/listdevs.c -Ilibusb -Ilibusb/os -Iexamples -lpthread -ludev -g -o listdevs",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
此时可以菜单栏Terminal->Run Build Task...进行编译
3.3调试配置
安装c++扩展
创建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}/listdevs",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
点击Run->Start Debugging
自动停在了main函数处
可以使用如下按钮进行执行控制,这样比直接使用gdb命令行调试更方便一些,阅读代码也更方便直观。
使用vscode轻量高效,推荐使用该方法。
得益于改开发板强劲的性能和完善的开发环境,可以直接将开发板作为开发主机进行来发,
并且基于vscode可以实现轻量化的ide开发,比命令行开发调试更高效,又避免了交叉开发的繁琐。