How to setup Go in GoClipse

huangapple go评论108阅读模式
英文:

How to setup Go in GoClipse

问题

我在我的eclipse中安装了goclipse,并按照以下方式设置了首选项:

首选项->Go->工具

项目资源管理器

现在,当我创建一个新的Go文件(HelloWorld.src),该文件保存在D:/GO/TestProject/src中。但是当我构建相同的文件时,bin和pkg文件夹为空,因此当我运行该文件时会出现以下错误:

资源没有对应的go包

因此,由于这个错误,无法运行代码。

英文:

I installed goclipse in my eclipse, and setup the preferences as follows :

Preferences->Go->Tools

ProjectExplorer

Now when I create a new GoFile (HelloWorld.src), the file is saved in D:/GO/TestProject/src. But when I build the same file, the bin and pkg folders are empty and hence when I run the file the following error comes :

resource does not have a corresponding go package

Unable to run the code because of this error.

答案1

得分: 0

你的项目路径应该是D:\GO\src\TestProject,以便与工作区的预期匹配,如https://golang.org/doc/code.html所述。

然后,你的GOPATH应该指向D:\GO(而不是...\src)。
go工具将根据情况自动使用$GOPATH/src$GOPATH/bin$GOPATH/pkg

正如icza指出的那样,你的程序应该在go文件的顶部有一个package main语句,以便被识别为可执行文件,除非你想创建一个包,在这种情况下,你应该根据需要命名你的包。

英文:

Your project path should be D:\GO\src\TestProject in order to match the workspace expected as described in https://golang.org/doc/code.html

Then, your GOPATH should point to D:\GO (NOT ...\src)
The go tool will automatically use $GOPATH/src, $GOPATH/bin or $GOPATH/pkg when appropiate for each case.

And as icza pointed out, your program should have a package main statement on the top of your go file to be recognized as an executable, unless you want to create a package, in that case, you should name your package as you want.

huangapple
  • 本文由 发表于 2016年11月25日 19:10:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/40803659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定