【发布时间】:2022-11-01 23:59:10
【问题描述】:
目标: 我想用 Raspberry Pi 400 在 Ubuntu 上设置 VScode 调试。
我做了什么: 我可以使用sudo ./program_name 编译和运行程序。我必须运行 sudo 否则我会收到权限被拒绝错误。我不想像通常不鼓励那样使用 root 权限运行 VScode。
问题:当我启动调试器(按 F5)并包含 wiringPi.h 时,我收到以下错误:
wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: Permission denied.
Aborting your program because if it can not access the GPIO
hardware then it most certianly won't work
Try running with sudo?
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-j40gmjsr.mas" 1>"/tmp/Microsoft-MIEngine-Out-vltmyj1b.a3g"
我的 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": "C/C++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
我应该怎么做才能使用我的设置启动调试器?我可以在 launch.json 文件中添加一些内容吗?
【问题讨论】:
-
如果您需要 root 权限来运行程序,您将需要相同的权限才能在调试器下运行程序。错误消息告诉你很多。
-
非常不鼓励以 root 权限运行 VScode。因此,是否可以以其他方式完成的问题。
-
围绕这个问题进行谷歌搜索,您似乎需要将自己添加到各个组以获得必要的权限,建议使用组 gpio 和 kmem。但我肯定不是专家。请谨慎接受此建议。
标签: c++ linux debugging visual-studio-code raspberry-pi