Home > Backend Development > Golang > After building correctly Main.go will not run

After building correctly Main.go will not run

WBOY
Release: 2024-02-09 13:00:08
forward
504 people have browsed it

正确构建后 Main.go 将不会运行

In this article, php editor Xinyi will introduce how to correctly build the Main.go file to avoid problems that cannot be run. Main.go is the main entry file of the Go language program. The built Main.go file is the key to running our program. However, if you don't pay attention to some details, it may cause the program to not run properly. Therefore, this article will explain in detail the steps and precautions for correctly building Main.go to help readers avoid running problems and ensure that the program runs smoothly.

Question content

I started to learn go and made a crm application, but found that after building main, it could not 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
Copy after login

I'm new to programming, github, etc., but I did my commits and pushes and everything was correct. Even cloned the code from my repository and tried again but nothing changed.

Solution

Your program is not executed correctly.

go build .\main.go
Copy after login

This command compiles and builds main.go. However, you generally should not pass filenames to go build. A better way is go build. But that's not your real problem...

go run .\main.exe
Copy after login

This command attempts to build and run a package named 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
Copy after login

tells you that the package named main.exe cannot be found in the current package.

If you want to execute the program compiled in the first command, just execute it as usual:

.\main.exe
Copy after login

The above is the detailed content of After building correctly Main.go will not run. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template