我已经在eclipse中安装了goclipse并创建了一个新的go项目。
现在这就是我所拥有的:
我有hello.go看起来像这样:
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
然后,我按下运行按钮,或右键单击文件hello.go,然后运行,它什么也没有。此外,它在bin文件夹中也为空。
然后我按下run configurations
按钮,那里只有一个项目名称,几乎是空的。它给:
Given Go package not found.
这是我的Go偏好设置:
我注意到GOROOT和GOPATH都与资源管理器中列出的不同,但是一旦将它们更改为C:\ Go \ src \ pkg或C:\ Go \ src,“应用和确定”按钮将被禁用。此外,我也没有C:\ Go \ src \ pkg文件夹。
I can go install
or go build
in command line, but I would like to use eclipse for another much larger project. It's windows 7, and the eclipse version is Luna Service Release 1 (4.4.1). Thank you.
EDIT: Now I have the following configurations, and it works fine: Go is installed at c:\Go in Preferences: GOROOT:C:\Go, GOPATH: C:\Users\Tiina\go_workspace The rest in Preferences is filled in automatically. helloTest project is located at C:\Users\Tiina\go_workspace\src\helloTest hello.go is located at C:\Users\Tiina\go_workspace\src\helloTest\hello.go Maybe because I create a project from existing code, and there was something left behind, it automatically adds another GOPATH, in Preferences delete it.
If GOROOT
refers to where go is installed (C:\Go
), then you need to make sure that:
GOPATH
differs from GOROOT
(it is important, because GOROOT/[src|pkg|bin]
are folders for the Go language itself, not for your own sources)GOPPATH
points to a folder under which all your different Go project will reside (for instance C:\Users\yourName\Go
: that defines a workspace)GOPATH\src\myproject
See "How to Write Go Code" to make sure that your installation and project sources respect the expected organization.
The OP Tiina reports in the comments:
Now it works, but I noticed two things odd.
- First what I did: I move
helloTest
folder intoC:\Users\Tiina\go_workspace\src
, so now it is atC:\Users\Tiina\go_workspace\src\helloTest
.- Then I create project from existing code. Nothing else changed. Now I have two
GOPATH
in explorer, one isC:\Users\Tiina\go_workspace\src
, the other one isC:\Users\Tiina\go_workspace\helloTest\src
.
The latter one did no exist at the beginning
I suspect what goclipse does is define one GOPATH
per project (or complete the existing GOPATH
).
If you create or import a project, it will define/complete GOPATH
in <that project/src>
If you hello.go is within that <that project/src/>
folder, then it should build and work as expected.
The user guide "project structure" of goclipse mentions:
项目位置不属于任何
GOPATH
条目。
在这种情况下,项目位置将隐式添加为一个条目的GOPATH
,和去工作空间结构的bin
,pkg
和src
目录将在项目中使用。请注意,项目的隐式
GOPATH
条目仅适用于该项目中的源模块。其他Goclipse项目将看不到它(除非该条目已显式添加到global中GOPATH
)。在该
src
文件夹中,您可以创建Go源文件,这些源文件将被编译成一个库包(放入pkg
)或可执行文件(放入bin
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句