5

As stated in the title, I have a problem running the Golang code on Eclipse. I'm currently using Mac, and I installed go by using homebrew.

Currently, the folder where go is installed is as follows.

/usr/local/Cellar/go/1.5.2/..

and after running Terminal and typing open ~/.bash_profile I added the following.

export GOROOT="/usr/local/Cellar/go/1.5.2/"
export PATH=$PATH:$GOROOT/bin

Am I still missing something else?

PS If I run the code using Terminal like go run main.go, I have absolutely no problem. The problem must be due to some misconfiguration in Eclipse.

MarshallLee
  • 1,290
  • 4
  • 23
  • 42
  • Never set GOROOT (unless you're certain you need it -- you don't here). You will need a GOPATH. – JimB Jan 13 '16 at 20:11
  • @JimB Then should I change that `GOROOT` to `GOPATH` in the `bach_profile`? – MarshallLee Jan 13 '16 at 20:12
  • No, your GOPATH should never be in GOROOT. Start here: https://golang.org/doc/code.html – JimB Jan 13 '16 at 20:14
  • My setup is GOROOT to /usr/local/go and GOPATH /Users/myname/go. I am using IntelliJ Idea. I am not really running any go from IDE but from iTerm. I find IDE using useful only because of autocomplete and references to some go lib (CMD+click). My projects are located at my $GOPATH/src. I am not sure that this will help you, maybe you will figure out from this. – pregmatch Jan 14 '16 at 08:23
  • It's very painful with eclipse to run golang , I tried a lot with eclipse then moved to Visual Studio Code which I never used earlier but it is light and fast to work with golang. I found visual studio code awesome IDE. – Lovin Jun 19 '21 at 05:58

4 Answers4

13

I had the same error. Putting the source file under a sub-folder in src fixed it.

Ahmad Bilal
  • 131
  • 1
  • 3
5

Go to 'Run Configurations' -> Filter with Go Application -> select your project and then click the Environment tab, then click on select button and tick the GOPATH environment. select apply and then Run.

Venugopal V
  • 51
  • 1
  • 3
1

I had the same problem and I did two things to solve it:

  1. I opened Run configurations, filtered using "Go" and created a new configuration (right click on "Go Application" as a result of the filter). In the Environment tab added a new variable: GOPATH = [path to your workspace].
  2. I had .go files right under src folder, and this is wrong. I created a folder under src folder and moved .go files to that folder.

The first step could be replaced by creating a system environment and adding it to the list using the "Select" option instead of creating a new one. I prefered to create a new one so I can run differente projects in the same laptop without having to change the value of the system environment.

Rubén M.
  • 23
  • 5
0

Because the executable path is not right.
GoClipse compiles source into $project/bin, so we must set GOPATH = $project

Select project > Alt+Enter > Go Compiler > Use project specific settings > Eclipse GOPATH

In my case of wiki tutorial, GOPATH = :/home/sovann/go/wiki.
Then the IDE is able to locate /home/sovann/go/wiki/bin/main

  • 3
    I am using GoClipse on Windows 10. My golang is installed in "F:\Go" and I created a Go Project named as "HelloWorld" in "E:\Users\User\Desktop\workspace\HelloWorld", so I set GOROOT to "F:\Go" and GOPATH to "E:\Users\User\Desktop\workspace\HelloWorld". However, I got "Resource doesn't have a corresponding Go package” when I run the file. How can I solve it? – Casper May 19 '16 at 11:30