gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:50:27 26 4
gpt4 key购买 nike

在 OS X Mavericks 上将 GoClipse v0.80 安装到 Eclipse Luna 中...

在 Eclipse 的首选项中设置以下值 --> Go:

GOROOT:/usr/local/goGOPATH:/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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com