报错内容:
EACCES: permission denied, rename '/home/wen/.vscode-server/extensions/.b61b1c7c-f703-4dfd-bdc5-d9a00681c4b7' -> '/home/wen/.vscode-server/extensions/ms-vscode.cpptools-1.17.5-linux-x64'
解决办法:
升级wsl到wsl2就好了。
(1)使用管理员打开cmd,输入如下命令
wsl -l -v
输出如下:
NAME STATE VERSION
* Ubuntu-18.04 Stopped 1
(2)以上输出说明是wsl1,
启用虚拟机功能:桌面搜索框输入“启用或关闭Windows功能”
确保以下三个是打开状态:设置完毕需要重启
另外需要检查BIOS中是否开启了CPU 虚拟化功能,如果没有开启,参考:在BIOS中打开虚拟机 - 知乎 (zhihu.com)
(3)下载组件更新包,根据系统选择:
x64:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
arm64:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_arm64.ms
下载完毕运行。
(4) 在cmd中之下如下命令:
wsl --set-version Ubuntu-18.04 2
Ubuntu-18.04 是和上面查询出来的名称相同。
转换成功提示如上图所示。
再次查看,已经更新:
此时再次启动vscode,打开设置选项
再次搜索C/C++插件,就可以完成安装。
下载必要的C/C++开发编译器,cmake,gdb之后,配置快捷代码提示,这里直接放配置文件:
setting.json文件
{"[cpp]": {"editor.quickSuggestions": {"comments": "on","strings": "on","other": "on"}},"[c]": {"editor.quickSuggestions": {"comments": "on","strings": "on","other": "on"}},"C_Cpp.default.includePath": ["${workspaceFolder}/**","/usr/include/**"],"remote.WSL.fileWatcher.polling": true}
c_cpp_properties.json
{"configurations": [{"name": "Linux","includePath": ["${workspaceFolder}/**","/usr/include/**"],"defines": [],"compilerPath": "/usr/bin/gcc","cStandard": "c11","cppStandard": "c++98","intelliSenseMode": "linux-gcc-x64"}],"version": 4
}
代码提示如下: