在 OS X Mavericks 上将 GoClipse v0.80 安装到 Eclipse Luna 中...
在 Eclipse 的首选项中设置以下值 --> Go:
GOROOT:/usr/local/go GOPATH:/DevProjects/Go/GoHello(下面有一个 src 文件夹)
我创建了一个 Go 项目(连同新的 Go 文件)并将以下代码放入 src/Hello.go 中:
package src
import "fmt"
func main() {
fmt.Println("Hello")
}
当我运行 Hello.go 时,在 Eclipse 控制台中会出现以下内容:
************ Running Go build for project: GoHello ************
************ Build terminated. ************
它怎么不打印 Hello 到标准输出?
最佳答案
你需要package main
:
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
输出:
Hello
The Go Programming Language Specification
A complete program is created by linking a single, unimported package called the
main
package with all the packages it imports, transitively. Themain
package must have package namemain
and declare a functionmain
that takes no arguments and returns no value.func main() { … }
Program execution begins by initializing the
main
package and then invoking the functionmain
. When that function invocation returns, the program exits. It does not wait for other (non-main
) goroutines to complete.
关于eclipse - 不要使用 GoClipse 制作二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24481541/