Chocolatey是windows下的包管理器,相似ubuntu的apt,centos的yum。git
使用管理員權限打開命令行窗口,粘貼如下命令便可github
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
複製代碼
安裝完輸入choco測試是否出現了版本號golang
接下來安裝git golang及windows下的編譯環境mingwshell
choco install gitubuntu
choco install golangwindows
choco install mingwcentos
實際使用的過程當中用mingw貌似有問題,編譯通不過,會報如下錯誤bash
go build runtime/cgo: C:\Go\pkg\tool\windows_amd64\cgo.exe: exit status 2
複製代碼
後來google一番,mingw最新更新的時間仍是2017年,比較老了。 mingw-w64是在它基礎上改進的項目,最新更新的時間是3天前,而且網上都推薦使用這個。架構
下載地址:sourceforge.net/projects/mi… 安裝的時候注意選擇x86-64的架構:測試
安裝完了,鍵入gcc -v查看版本信息
設置環境變量並checkout go-ethereum源碼
C:\Users\xxx> set "GOPATH=%USERPROFILE%"
C:\Users\xxx> set "Path=%USERPROFILE%\bin;%Path%"
C:\Users\xxx> setx GOPATH "%GOPATH%"
C:\Users\xxx> setx Path "%Path%"
C:\Users\xxx> mkdir src\github.com\ethereum
C:\Users\xxx> git clone https://github.com/ethereum/go-ethereum src\github.com\ethereum\go-ethereum
C:\Users\xxx> cd src\github.com\ethereum\go-ethereum
C:\Users\xxx> go get -u -v golang.org/x/net/context
複製代碼
使用如下命令安裝
C:\Users\xxx\src\github.com\ethereum\go-ethereum> go install -v ./cmd/...
複製代碼
最後會在GOPATH的bin目錄下生成二進制geth.
開始是按goland默認的模板對cmd/geth/main.go文件進行debug,會報如下錯誤
後來發現不能debug file,要debug package,如圖所示,run kind 指定爲package:如圖所示,成功編譯並運行至斷點處。
以後就能夠愉快地調試了 ^ ^