不要使用GoClipse来制作二进制文件。

huangapple go评论67阅读模式
英文:

Go not making binary using GoClipse

问题

已将您提供的内容翻译为中文:

将GoClipse v0.80安装到OS X Mavericks上的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控制台中出现以下内容:

************  正在运行GoHello项目的构建  ************
************  构建已终止  ************

为什么它没有将Hello打印到标准输出(stdout)?

英文:

Installed GoClipse v0.80 into Eclipse Luna on OS X Mavericks...

Set the following values inside Eclipse's Preferences --> Go:

GOROOT: /usr/local/go
GOPATH: /DevProjects/Go/GoHello (this has a src folder underneath it)

I created a Go project (along with new Go file) and put the following code inside src/Hello.go:

package src

import "fmt"

func main() {
     fmt.Println("Hello")
}

When I run Hello.go, inside the Eclipse Console this what appears:

************  Running Go build for project: GoHello  ************
************  Build terminated.  ************

How coming its not printing Hello to stdout?

答案1

得分: 7

你需要 package main

package main

import "fmt"

func main() {
     fmt.Println("Hello")
}

输出结果:

Hello

> Go编程语言规范
>
> 程序执行
>
> 通过将一个名为 main 的单个未导入的包与其导入的所有包进行链接,可以创建一个完整的程序,这些包是传递性的。main 包必须具有包名 main,并声明一个不带参数且不返回值的函数 main
>
> func main() { … }
>
> 程序的执行从初始化 main 包开始,然后调用函数 main。当该函数调用返回时,程序退出。它不会等待其他(非 main)goroutine 完成。

英文:

You need package main:

package main

import "fmt"

func main() {
     fmt.Println("Hello")
}

Output:

Hello

> The Go Programming Language Specification
>
> Program execution
>
> A complete program is created by linking a single, unimported package
> called the main package with all the packages it imports,
> transitively. The main package must have package name main and declare
> a function main that takes no arguments and returns no value.
>
> func main() { … }
>
> Program execution begins by initializing the main package and then
> invoking the function main. When that function invocation returns, the
> program exits. It does not wait for other (non-main) goroutines to
> complete.

huangapple
  • 本文由 发表于 2014年6月30日 08:33:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/24481541.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定