rust 开发调试环境搭建vscode

我不是女神ヾ 2022-10-28 04:57 305阅读 0赞

linux

rust install

https://www.rust-lang.org/tools/install

vscode install

https://code.visualstudio.com/download

安装插件

rust-analyzer

这个插件比rust要更好用一些
https://rust-analyzer.github.io/

CodeLLDB

https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

windows

安装c/c++ 编译工具

如果不安装,后面在编译时,会报错说”link.exe”无法找到

https://visualstudio.microsoft.com/downloads/\#other

All Downloads ->Build Tools for Visual Studio 2019->download 下载安装包

运行安装包打开的visual studio 安装工具中选择 c++ 生成工具完成安装

rust install

https://www.rust-lang.org/tools/install

vscode install

https://code.visualstudio.com/download

安装插件

rust-analyzer

首先从源码安装rust-analyzer

  1. $ rustup component add rust-src
  2. # clone the repo
  3. $ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer
  4. # install both the language server and VS Code extension
  5. $ cargo xtask install

或者下载二进制文件后在vscode中配置下路径
{ “rust-analyzer.server.path”: “~/.local/bin/rust-analyzer-linux” }

这个插件比rust要更好用一些
https://rust-analyzer.github.io/

C/C++

https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

Configure VS Code

debug

Click Debug -> Add Configuration

If you’re on Windows then select C++ (Windows)

If you’re on Mac or Linux then select LLDB: Custom Launch

This should create and open launch.json. You’ll have to manually change the executable name under “program”.

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "(Windows) Launch",
  6. "type": "cppvsdbg",
  7. "request": "launch",
  8. "program": "${workspaceRoot}/target/debug/foo.exe",
  9. "args": [],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceRoot}",
  12. "environment": [],
  13. "externalConsole": true
  14. },
  15. {
  16. "name": "(OSX) Launch",
  17. "type": "lldb",
  18. "request": "launch",
  19. "program": "${workspaceRoot}/target/debug/foo",
  20. "args": [],
  21. "cwd": "${workspaceRoot}",
  22. }
  23. ]
  24. }

breakpoint

默认rust的文件无法打断点,需要使能下面的配置

File -> Preferences -> Settings 设置 “debug.showInlineBreakpointCandidates”: true

参考

https://www.forrestthewoods.com/blog/how-to-debug-rust-with-visual-studio-code/
https://code.visualstudio.com/docs/cpp/config-msvc
https://skyao.io/learning-rust/installation/windows.html
https://rust-analyzer.github.io/manual.html\#installation

发表评论

表情:
评论列表 (有 0 条评论,305人围观)

还没有评论,来说两句吧...

相关阅读