英文:
How to setup Go in GoClipse
问题
我在我的eclipse中安装了goclipse,并按照以下方式设置了首选项:
现在,当我创建一个新的Go文件(HelloWorld.src),该文件保存在D:/GO/TestProject/src中。但是当我构建相同的文件时,bin和pkg文件夹为空,因此当我运行该文件时会出现以下错误:
资源没有对应的go包
因此,由于这个错误,无法运行代码。
英文:
I installed goclipse in my eclipse, and setup the preferences as follows :
Now when I create a new GoFile (HelloWorld.src), the file is saved in D:/GO/TestProject/src. But when I build the same file, the bin and pkg folders are empty and hence when I run the file the following error comes :
resource does not have a corresponding go package
Unable to run the code because of this error.
答案1
得分: 0
你的项目路径应该是D:\GO\src\TestProject
,以便与工作区的预期匹配,如https://golang.org/doc/code.html所述。
然后,你的GOPATH应该指向D:\GO
(而不是...\src
)。
go工具将根据情况自动使用$GOPATH/src
、$GOPATH/bin
或$GOPATH/pkg
。
正如icza指出的那样,你的程序应该在go文件的顶部有一个package main
语句,以便被识别为可执行文件,除非你想创建一个包,在这种情况下,你应该根据需要命名你的包。
英文:
Your project path should be D:\GO\src\TestProject
in order to match the workspace expected as described in https://golang.org/doc/code.html
Then, your GOPATH should point to D:\GO
(NOT ...\src
)
The go tool will automatically use $GOPATH/src
, $GOPATH/bin
or $GOPATH/pkg
when appropiate for each case.
And as icza pointed out, your program should have a package main
statement on the top of your go file to be recognized as an executable, unless you want to create a package, in that case, you should name your package as you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论