eclipse - 不要使用 GoClipse 制作二进制文件

标签 eclipse macos go osx-mavericks goclipse

在 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

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.

关于eclipse - 不要使用 GoClipse 制作二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24481541/

相关文章:

javascript - Chrome找不到firefox和eclipse的功能

java - 哪个 Eclipse 与 ADT 完美配合?

ios - 使用 CGImage 的 JPEG 压缩质量

cocoa - 如何对 CGPath 的绘图进行动画处理?

java - eclipse运行java程序时出现内部错误

java - 如何在 Eclipse/Maven 中创建多模块项目 - 只是一个大项目

ios - Realm 对象服务器 MacOs 错误

node.js - 有人可以解释一下 GO lang 的架构吗,它比 Nodejs 更快吗?如果是的话,是什么让它更快

go - 接受 map 参数

go - slice 中的长度和容量方法