Main.go在正确构建后无法运行。

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

Main.go won't run after correct build

问题

我开始学习Go语言并制作了一个CRM应用程序,但在构建主程序后发现它无法运行。

这是终端显示的错误信息:

PS crm-go-fiber> go build .\main.go
PS crm-go-fiber> go run .\main.exe
main module (github.com/Lo0mi3x/crm-go-fiber) does not contain package github.com/Lo0mi3x/crm-go-fiber/main.exe

我对编程、GitHub等方面都很新手,但我已经进行了提交和推送,并且一切都正确。甚至从我的代码库中克隆了代码并再次尝试,但没有任何变化。

英文:

I started learning go and made a crm app, just to find that after building main, it won't run.

This is the error shown in the terminal:

PS crm-go-fiber> go build .\main.go
PS crm-go-fiber> go run .\main.exe
main module (github.com/Lo0mi3x/crm-go-fiber) does not contain package github.com/Lo0mi3x/crm-go-fiber/main.exe

I'm new at programming, GitHub, and stuff but I did my commit & push, and everything correct.
Even clone the code from my repository and tried it again, but no changes.

答案1

得分: 1

你正在错误地执行你的程序。

go build .\main.go

这个命令编译并构建了 main.go。然而,通常情况下不应该将文件名传递给 go build。更好的方法是只使用 go build。但是这并不是你实际的问题所在...

go run .\main.exe

这个命令试图构建并运行一个名为 main.exe 的包,该包位于当前目录中。你看到的错误信息是:

main 模块 (github.com/Lo0mi3x/crm-go-fiber) 不包含包 github.com/Lo0mi3x/crm-go-fiber/main.exe

这告诉你在当前包中找不到一个名为 main.exe 的包。

如果你想执行你在第一个命令中编译的程序,只需像平常一样执行它:

.\main.exe
英文:

You're executing your program incorrectly.

go build .\main.go

This command compiles and builds main.go. However, you should generally not pass filenames to go build. The better approach is simply go build. But that's not your actual problem here...

go run .\main.exe

This command attempts to build and run a package called main.exe located in the current directory. The error message you see:

main module (github.com/Lo0mi3x/crm-go-fiber) does not contain package github.com/Lo0mi3x/crm-go-fiber/main.exe

Is telling you that it cannot find a package caleld main.exe within your current package.

If you wish to execute the program you compiled in the first command, just execute it as normal:

.\main.exe

huangapple
  • 本文由 发表于 2023年6月16日 18:26:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76489287.html
匿名

发表评论

匿名网友

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

确定