英文:
Golang on eclipse: "Resource doesn't have a corresponding Go package" on Mac
问题
如标题所述,我在Eclipse上运行Golang代码时遇到了问题。我目前使用的是Mac,并通过homebrew安装了go。
当前,go安装的文件夹路径如下:
/usr/local/Cellar/go/1.5.2/..
在运行终端并输入open ~/.bash_profile
后,我添加了以下内容:
export GOROOT="/usr/local/Cellar/go/1.5.2/"
export PATH=$PATH:$GOROOT/bin
我还漏掉了其他什么吗?
附注 如果我在终端中使用go run main.go
运行代码,完全没有问题。问题肯定是由于Eclipse中的某些错误配置导致的。
英文:
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.
答案1
得分: 13
我遇到了同样的错误。将源文件放在src的子文件夹下解决了这个问题。
英文:
I had the same error. Putting the source file under a sub-folder in src fixed it.
答案2
得分: 5
前往“运行配置” -> 使用Go应用程序进行筛选 -> 选择您的项目,然后点击“环境”选项卡,接着点击“选择”按钮并选中GOPATH环境变量。点击应用,然后点击运行。
英文:
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.
答案3
得分: 1
我遇到了同样的问题,我采取了两个步骤来解决它:
- 我打开了运行配置,使用“Go”进行筛选,并创建了一个新的配置(右键单击“Go Application”以进行筛选结果)。在环境选项卡中添加了一个新的变量:GOPATH = [您的工作区路径]。
- 我的.go文件直接放在src文件夹下,这是错误的。我在src文件夹下创建了一个文件夹,并将.go文件移动到该文件夹中。
第一步可以通过创建系统环境并使用“选择”选项将其添加到列表中来替代,而不是创建一个新的环境变量。我更喜欢创建一个新的环境变量,这样我可以在同一台笔记本电脑上运行不同的项目,而无需更改系统环境变量的值。
英文:
I had the same problem and I did two things to solve it:
- 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].
- 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.
答案4
得分: 0
由于可执行路径不正确。
GoClipse将源代码编译到$project/bin目录中,所以我们必须设置GOPATH = $project。
选择项目 > Alt+Enter > Go Compiler > 使用项目特定设置 > Eclipse GOPATH。
在我这个wiki教程中,GOPATH = :/home/sovann/go/wiki
。
然后IDE就能够找到/home/sovann/go/wiki/bin/main。
英文:
Because the executable path is not right.<br/>
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
.<br/>
Then the IDE is able to locate /home/sovann/go/wiki/bin/main
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论