MarshallLee
MarshallLee

Reputation: 1330

Golang on eclipse: "Resource doesn't have a corresponding Go package" on Mac

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.

Upvotes: 5

Views: 13260

Answers (4)

Rubén M.
Rubén M.

Reputation: 23

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.

Upvotes: 1

Ahmad Bilal
Ahmad Bilal

Reputation: 131

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

Upvotes: 13

Venugopal V
Venugopal V

Reputation: 51

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.

Upvotes: 5

Sovannrith Lay
Sovannrith Lay

Reputation: 1

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

Upvotes: 0

Related Questions