VS Code + WSL2 搭建 xv6-labs 开发环境

标签: 环境搭建 发布于:2023-01-19 12:25:27 编辑于:2023-02-05 15:06:06 浏览量:1285

概述

踩了好多坑,值得记录一下。

WSL2 的代理设置

.bashrc 里的设置:

setup_proxy () {
  export ALL_PROXY="http://$(hostname).local:7890"
  export http_proxy="http://$(hostname).local:7890"
  export https_proxy="http://$(hostname).local:7890"
  export no_proxy=localhost
}

WSL2 和 WSL 不一样,其不再直接能访问宿主机的端口, 并且也不能直接使用 ipconfig 查询到的虚拟局域网的 IP,因为这个是会变的。 所以上面使用的是 $(hostname).local7890 是我本机代理的暴露端口。

为什么上面要用到函数的形式呢?原因在于 VS Code 的 WSL 插件会在 WSL 内设置代理后变得无法使用, 表现为巨卡无比,插件列表要加载一万年,代码提示和跳转都无法使用。

Clangd 基本设置

完成本步骤后 VS Code 的代码提示功能以及代码跳转功能应当可用。

  1. 在 VS Code 中安装 C/C++ & clangd 插件。
  2. 在 WSL 中安装 clangd
    sudo apt-get install clangd-12
    sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-12 100
    
  3. clangd 生成 compile_commands.json
    sudo apt-get install bear
    bear -- make qemu  # Ctrl + A X to exit
    
    注意,如果没有生成成功原因可能在于你之前已经执行过 make 了,在相关源代码中随便加一个空行再执行上述命令即可。

参考

  1. https://superuser.com/questions/1679757/how-to-access-windows-localhost-from-wsl2
  2. https://blog.csdn.net/weixin_43862847/article/details/128149742

未经允许,禁止转载,本文源站链接:https://iamazing.cn/