windows下 rust 调试环境的坑
学习语言的第一步是弄好环境。可是我弄完环境老忘记。所以还是整理下这些坑。来一些报错集锦。
第一个坑 :note: the msvc targets depend on the msvc linker but `link.exe` was not found note: please ensure that VS 2013, VS 2015, VS 2017, VS 2019 or VS 2022 was installed with the Visual C++ option
windows下要装msvc,不然你连cargo new都搞不了。首要任务就是
终端运行这两个命令解决:
rustup default stable-x86_64-pc-windows-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
第二个坑:要装C++调试工具
我用cargo new hi 这个文件以后 记得用vscode打开这个文件夹

第三个坑 :下一个插件,其他的一些插件该下的下,但这个一定要下载一个。

好了,可以按f5了。记得选择windows版本。关于LLDB啥的,不需要,你用的是window版本,其他系统可能需要。

选这个添加配置,这个调试的时候必做的步骤。

打开后就这样子了,launch:program"does not exit.

需要往launch.json里面塞东西先按网上的乱塞。
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) 启动",
"preLaunchTask": "build",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]
}
第四个坑:找不到任务"找不到任务build",选择配置任务。看到.vscode了嘛,因为刚才配置launch生成的,待会儿也会生成一个。

选这个

自动生成的改成这个,照网上抄的。
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "gdb",
"preLaunchTask": "build",
"request": "launch",
"target": "${workspaceFolder}/target/debug/${workspaceFolderBasename}",
"cwd": "${workspaceFolder}"
}
]
}

然后回到main.rs继续按F5

这次选择这个仍要调试

第五个坑:调试执行了,出现这个 密钥“externalConsole”已弃用。请改用“console”。

需要改launch.json里面的最后一条代码。
改成:"console": "externalTerminal"

踩完坑了。终于可以正常运行了。耗时4小时。
大家可以愉快的玩耍了。
