eclipse 上的 Golang:Mac 上的“资源没有相应的 Go 包”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34775953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Golang on eclipse: "Resource doesn't have a corresponding Go package" on Mac
提问by MarshallLee
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.
如标题所述,我在 Eclipse 上运行 Golang 代码时遇到问题。我目前使用的是 Mac,我使用自制软件安装了 go。
Currently, the folder where go is installed is as follows.
目前安装go的文件夹如下。
/usr/local/Cellar/go/1.5.2/..
/usr/local/Cellar/go/1.5.2/..
and after running Terminal and typing open ~/.bash_profile
I added the following.
在运行终端并输入后,open ~/.bash_profile
我添加了以下内容。
export GOROOT="/usr/local/Cellar/go/1.5.2/"
export PATH=$PATH:$GOROOT/bin
Am I still missing something else?
我还缺少其他东西吗?
PSIf 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.
PS如果我使用 Terminal like 运行代码go run main.go
,我绝对没有问题。问题一定是由于 Eclipse 中的一些错误配置造成的。
回答by Ahmad Bilal
I had the same error. Putting the source file under a sub-folder in src fixed it.
我有同样的错误。将源文件放在 src 的子文件夹下修复了它。
回答by Venugopal V
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.
转到“运行配置”-> 使用 Go 应用程序过滤-> 选择您的项目,然后单击环境选项卡,然后单击选择按钮并勾选 GOPATH 环境。选择应用,然后运行。
回答by Sovannrith Lay
Because the executable path is not right.
GoClipse compiles source into $project/bin, so we must set GOPATH = $project
因为可执行路径不对。
GoClipse 将源码编译成 $project/bin,所以我们必须设置 GOPATH = $project
Select project > Alt+Enter > Go Compiler > Use project specific settings > Eclipse GOPATH
选择项目 > Alt+Enter > Go Compiler > 使用项目特定设置 > 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
在我的 wiki 教程中,GOPATH = :/home/sovann/go/wiki
.
然后IDE就可以找到/home/sovann/go/wiki/bin/main
回答by Rubén M.
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.
- 我打开了运行配置,使用“Go”过滤并创建了一个新配置(作为过滤器的结果,右键单击“Go Application”)。在 Environment 选项卡中添加了一个新变量:GOPATH = [path to your workspace]。
- 我在 src 文件夹下有 .go 文件,这是错误的。我在 src 文件夹下创建了一个文件夹并将 .go 文件移动到该文件夹中。
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.
第一步可以通过创建系统环境并使用“选择”选项将其添加到列表中来代替,而不是创建一个新环境。我更喜欢创建一个新的,这样我就可以在同一台笔记本电脑上运行不同的项目,而不必更改系统环境的值。