英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论