欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

在Eclipse上编写Go项目

程序员文章站 2022-07-01 20:38:50
Note for users in China Note: if you are behind the Great Firewall of China, you are very likely to encounter problems installing GoClipse: blocked co ......

在Eclipse上编写Go项目 Note for users in China

Note: if you are behind the Great Firewall of China, you are very likely to encounter problems installing GoClipse: blocked connections, timeouts, or slow downloads. This is because the update site is hosted in Github, which is blocked or has limited access. These alternative instructions should let you perform the installation:

  1. Download an Eclipse installation which already contains CDT (such as the "Eclipse IDE for C/C++ Developers" package), so CDT doesn't have to be downloaded during installation.
  2. Download the website from , unpack the archive and use the releases directory as a Local repository instead of the Update Site URL. Uncheck the option "Contact all updates sites during installation to find required software" so only the local repository is used.
  • Note however: you will likely need to re-download the archive above whenever you want to update GoClipse to a newer version.

由于GFW的原因,不FQ下载会各种报错。所以我按照官网教程说明成功完成了安装。GOROOT和GOPATH可以在安装完后查看(不能相同)。

 

不知道是不是仍然是墙的原因,gocode、godef以及guru下载都出现了问题。

 

CSDN里提供的exe都需要积分,所以我觉得还是直接找github地址下载zip文件。

 

gocode:

https://github.com/nsf/gocode 下载完后解压为gocode,然后在根目录里执行go build得到gocode.exe

guru:

https://github.com/golang/tools 下载完后解压为$GOPATH$\src\golang.org\x\tools,然后在根目录里执行go build得到guru.exe

godef:

https://github.com/rogpeppe/godef 下载完后解压为$GOPATH$\src\github.com\rogpeppe\godef,然后在根目录里执行go build得到godef.exe

 

3个编译好的exe可以在文末链接中下载。

 

eclipse上配置完Go的安装路径以及三个exe的位置后,点击apply即可。

 

新建完Go项目后主要看bin以及src文件夹,bin中存放的是编译好之后的exe文件,src存的是源代码。

 

不能直接在src下创建go文件,而且必须在src在创建main文件夹,在main文件夹下创建package为main的主文件(如hello.go)

一个package下,只能有一个main方法,不管是在那个文件中,但是只能有一个,这个package是按照文件夹区分的,所以package名应该与文件夹名相同。

 

项目build之后能够在bin中看见main.exe,run直接执行。

 

https://pan.baidu.com/s/1URpwesND1H5R713o5gP-jg