简体   繁体   English

如何在GoClipse中设置Go

[英]How to setup Go in GoClipse

I installed goclipse in my eclipse, and setup the preferences as follows : 我在eclipse中安装了goclipse,并按如下所示设置首选项:

Preferences->Go->Tools 首选项- >转到- >工具

ProjectExplorer ProjectExplorer

Now when I create a new GoFile (HelloWorld.src), the file is saved in D:/GO/TestProject/src. 现在,当我创建一个新的GoFile(HelloWorld.src)时,该文件将保存在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 : 但是,当我构建相同的文件时,bin和pkg文件夹为空,因此,当我运行文件时,出现以下错误:

resource does not have a corresponding go package 资源没有相应的go包

Unable to run the code because of this error. 由于此错误,无法运行代码。

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 您的项目路径应为D:\\GO\\src\\TestProject ,以匹配预期的工作空间,如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. 然后,您的GOPATH应该指向D:\\GO (NOT ...\\src )每种情况下,go工具都会自动使用$GOPATH/src$GOPATH/bin$GOPATH/pkg

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. 就像icza所指出的那样,除非您要创建包,否则您的程序应该在go文件的顶部具有package main语句,以被识别为可执行文件,在这种情况下,应根据需要命名包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM