MIT6.824环境搭建:wls+vs code
背景
尝试学习MIT 6.824分布式系统,他们的实验使用的是go语言,并且不支持window。打算使用wls+vs code搭建开发环境。这里做记录。
步骤
WLS安装
在管理员 PowerShell ,输入wsl --install
即可安装Ubuntu。这里不做介绍了
按照提示重启后,PowerShell 里面会自动添加Ubuntu的便签页,填入username和password即可进入linux
Vscode安装+WLS调试
下载最新版vscode:略。
vscode安装remote-wsl
,用于WSL互联。
在wsl中,输入 code .
即可直接调用vscode。可以看到有一个绿色的方框在下面,即wsl和vs code环境已经调通。
实验Go环境配置
安装GO环境
改动点:
- 教案中,go程序包的地址修改为如下
# 下载go 1.13.6 并解压到/usr/loacl
$ wget -qO- https://go.dev/dl/go1.13.6.linux-amd64.tar.gz | sudo tar xz -C /usr/local
12
- go添加到环境变量、go镜像国内代理到
~/.profile
# Config Go ENV
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOPROXY=https://goproxy.cn
export GO111MODULE=on
# Merge PATH
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
1234567
下载代码,编译执行
教案步骤如下:
改动点:
- 安装gcc
由于ubuntu默认没有gcc,导致go build -buildmode=plugin ../mrapps/wc.go
命令时候编译报错。安装gcc
sudo apt-get install build-essential
1
terminal调试mrsequential.go
terminal调试成功表示goland环境已经ok
vscode+wsl调试mrsequential.go
- 添加
.vscode/launch.json
,控制mrsequential.go debug
{
// 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": [
{
"debugAdapter": "dlv-dap",
"name": "mrsequential",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/src/main/mrsequential.go",
"args": ["wc.so","pg-grimm.txt"]
}
]
}
debug问题点
cannot load plugin wc.so
原本vscode+wsl也很容易。wsl+vscode debug时候无法load plugin wc.so
debug后,把错误码输出:cannot load plugin wc.so
由于对go不熟悉,折腾了gopath、go mod,还换成了2022实验代码+goland 1.17。最后发现编译插件wc.so的参数需要和启动参数一致,否者无法正常加载
build时候添加-gcflags="all=-N -l"
,这样就可以解决。
go build -buildmode=plugin -gcflags="all=-N -l" ../mrapps/wc.go
开启竞争检测-race
开始竞争保证go build
生成插件和go run
参数一致,否者也会cannot load plugin wc.so
go build -race -buildmode=plugin -gcflags="all=-N -l" ../mrapps/wc.go
vscode .vscode/launch.json
添加"buildFlags": "-race"
{
// 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": [
{
"debugAdapter": "dlv-dap",
"name": "mrsequential",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/src/main/mrsequential.go",
"args": ["wc.so","pg-grimm.txt"],
"buildFlags": "-race"
}
]
}
debug调试正常