go開發工具goclipse的安裝


(1) 安裝Eclipse

建議下載Eclipse時直接下載“Eclipse IDE for Java Developers”的package,而不要下載較小的Installer。因為Installer在安裝Eclipse時還要聯網下載,因為科學上網的原因,聯網下載會非常慢甚至失敗。
Eclipse package下載地址:http://www.eclipse.org/downloads/eclipse-packages/

(2) 安裝GoClipse

可以采取在線安裝的方式或離線的方式安裝。
我采用在線安裝的方式可以安裝成功,如果因為網絡的原因,可選離線安裝方式。
GoClipse安裝指南:https://github.com/GoClipse/goclipse/blob/latest/documentation/Installation.md#installation

Start Eclipse, go to Help -> Install New Software...
Click the Add... button, then enter the Update Site URL: http://goclipse.github.io/releases/ in the Location field, click OK.
Select the recently added update site in the Work with: dropdown. Type GoClipse in the filter box. Now the Goclipse feature should appear below.
Select the GoClipse feature, make sure "Contact all update sites during install to find required software" is enabled, and complete the wizard.
Dependencies such as CDT will automatically be added during installation.

(3) 配置GoClipse

  • 在Eclipse中,打開Windows -> Preferences,找到Go,在Go installation中輸入Go SDK的C:\Go目錄。

在C:\Go目錄下創建一個子目錄,比如work,在Eclipse GOPATH中輸入C:\Go\work。


下面會在C:\Go\work這個目錄下編譯Go的其它工具。

  • 打開Go -> Tools。對gocode和godef可以點擊Download按鈕來從GitHub直接下載。


但是對guru,直接Download會失敗,因為Download時試圖去從Golang官網下載,而Golang官網已經被拉黑了。
不過因為Golang的代碼都是托管在GitHub上的,所以我們可以通過下面的地址來下載Go tools的源代碼。
https://github.com/golang/tools
下載后,在C:\Go\work\src目錄下創建golang.org/x的目錄結構,並將上一步git clone的Go tools的tools目錄復制到golang.org/x目錄下。

 git clone https://github.com/golang/tools.git

  • 在C:\Go\work\bin目錄下,在命令行中執行(以GitBash為例)

export GOPATH="C:\Go\work"
go build golang.org/x/tools/cmd/guru

/c/Go/bin/go.exe build golang.org/x/tools/cmd/guru


執行命令成功后guru.exe就會生成在C:\Go\work\bin目錄下。

  • 最后在Eclipse中設置好guru。

  • 在Eclipse中寫第一個Go程序
    在Eclipse中新建一個Go project,再在src下創建一個hello目錄,再在hello目錄下新建一個hello.go的Go file。內容如下所示:


右鍵Run as -> Go Application。

如果出錯“Executable … doesn’t exist“,請檢查hello.go的第一行是否為package main,Go需要從main package作為程序入口,這一點和Java程序是不同的。

參考文章:

使用Eclipse和GoClipse作為Go開發IDE


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM