Go – 无法编译 hello world(Windows)

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

Go - cannot compile hello world (Windows)

问题

只返回翻译好的部分:

只是尝试使用Go,但是我无法编译我的第一个程序。这导致了一系列关于编译器的问题。

它包含在这个单独的文件中:

"D:\programming\Go\src\mytest\mytest.go"

程序文本如下:

// mytest project mytest.go
package mytest

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
}

在包文件夹中,我尝试了以下命令:

>go build

没有任何输出。根据go help build的说明,这是预期的结果。

>go build -v
_/D_/programming/Go/src/mytest

_/D_/是什么东西?看起来像是一个新发明!

最奇怪的是:

>go build -v mytest
无法加载包:包mytest:导入"mytest":找不到包

那么我做错了什么,如何编译这个东西?

英文:

Just trying out Go, but I can't get it to compile my very first program. This caused a bunch of questions on the compiler.

It is contained in this single file:

"D:\programming\Go\src\mytest\mytest.go"

the program text is:

// mytest project mytest.go
package mytest

import "fmt"

func main() {
	fmt.Println("Hello, Go!")
}

In the package folder I tried the following commands:

>go build

says nothing. According to go help build this is the intended result.

>go build -v
_/D_/programming/Go/src/mytest

What are the _/D_/ things are??? Looks like a new invention!

And the most strange one:

>go build -v mytest
can't load package: package mytest: import "mytest": cannot find package

So what am I doing wrong and how do I get the thing compiled?

答案1

得分: 8

main函数在程序中必须位于main包中。main包可以导入其他包并调用它们。

英文:

The main function in a program must be in package main. Package main can then import other packages and call them.

huangapple
  • 本文由 发表于 2012年8月14日 17:02:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/11949007.html
匿名

发表评论

匿名网友

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

确定