I have installed goclipse in my eclipse and created a new go project.
Now this is what I have:
And I have hello.go looks like this:
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
Then I press run button, or right click the file hello.go, and then run, it gives nothing. Besides, it is also empty in bin folder.
Then I press run configurations
button, almost empty there with only a project name. it gives:
Given Go package not found.
This is my Preferences for Go:
I noticed that both GOROOT and GOPATH are different from those listed in explorer, but once I changed them to C:\Go\src\pkg or C:\Go\src, the Apply and OK button becomes disabled. Besides, I don't have C:\Go\src\pkg folder either.
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:
The project location is not part of any
GOPATH
entry.
In this case the project location will implicitly be added as an entry to theGOPATH
, and a Go workspace structure with thebin
,pkg
, andsrc
directories will be used in the project.Note that the project's implicit
GOPATH
entry will only apply to the source modules in that project. It will not be visible to other Goclipse projects (unless the entry is explicitly added to the globalGOPATH
).In the
src
folder you can create Go source files that will be compiled into a library package (and placed intopkg
), or into an executable (and placed inbin
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With