Go:錯誤 could not launch process: EOF 解決

candyleer發表於2019-02-23

問題

當我興致勃勃的開始 go 語言的 hello world 的時候, 驀然回首

package main

import "fmt"

func main() {
	var i = 1
	fmt.Println("hello world ", i)
}
複製程式碼

卻發現, 竟然不能 debug....

could not launch process: EOF
Process exiting with code: 1
複製程式碼
  • 系統: mac OSX 10.13.3/4/5
  • IDE :IntelliJ IDEA 仔細 google 了一番,貌似是 CommandLineTools 更新後的問題.

解決方案

Solution 1(推薦)

感謝Nob東瓜提供,用新版的 dlv 替換 idea 提供的舊版的(舊版dlv bug導致的,編譯最新的dlv替換idea自帶的即可).

  1. dlv 專案地址github.com/derekparker… 2.安裝最新的 dlv.
go get -v  -u github.com/derekparker/delve/cmd/dlv
cd $GOPATH/src/github.com/derekparker/delve
make install
複製程式碼

完成後

➜  delve git:(master) make install
scripts/gencert.sh || (echo "An error occurred when generating and installing a new certificate"; exit 1)
go install -ldflags="-s -X main.Build=9a216211d3461ab031f822c012bc27cab9758da0" github.com/derekparker/delve/cmd/dlv
codesign -s "dlv-cert"  /usr/local/Cellar/go/1.10.3/libexec/bin/dlv
複製程式碼
  1. 替換檔案
cd '/Users/{user}/Library/Application Support/IntelliJIdea2017.2/intellij-go/lib/dlv/mac'
mv dlv dlv_back
ln -s $GOROOT/bin/dlv dlv
複製程式碼

$GOROOT/bin/dlv 指向的檔案就是/usr/local/Cellar/go/1.10.3/libexec/bin/dlv

如果你用的 Goland 同樣的道理

cd /Applications/GoLand.app/Contents/plugins/intellij-go-plugin/lib/dlv/mac
mv dlv dlv_back
ln -s $GOROOT/bin/dlv dlv
複製程式碼

ps:貌似有些 goland 的路徑在/Applications/GoLand.app/Contents/plugins/go/lib/dlv/mac,自己試下就可以啦

哦了

Solution 2

  1. 刪除系統現有的CommandLineTools
sudo rm -rf /Library/Developer/CommandLineTools
複製程式碼
  1. 訪問 Apple 開發者工具 頁面,用 apple ID 登入後,下載 Command Line Tools (Mac OS 10.13) for Xcode 9.1 (Dec 6,2017)
    image.png
  2. 安裝完成後. Everything OK!
API server listening at: 127.0.0.1:50661
hello world  1

Debugger finished with exit code 0
複製程式碼

參考:

相關文章