In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what the compilation and execution process of Go is like, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
In this process, we use the go run command, which completes the whole process of source code from compilation to execution.
Today, we will introduce this process in detail. To put it simply, go run can be equivalent to go build + execution.
Brief introduction of build Command
In Golang, the build process is mainly performed by go build. It completes the compilation of the source code and the generation of executable files.
Go build receives a .go file or directory, and compiles all .go files in the current directory by default. Execution under the main package will generate the corresponding executable file. Under the non-main package, it will do some checks. The generated library files will be placed in the cache directory, and no new files will be generated in the working directory.
Create a new hello case
Before formally introducing the compilation process, re-demonstrate the Hello World case and create a new hello.go file as follows:
Package mainimport "fmt" func main () {fmt.Println ("Hello World")}
Execute go build hello.go and generate the executable file hello under the directory. Execute hello and output Hello World.
Introduce build options
The demo of the compilation process requires the assistance of several options provided by go build to perform a go help build view. As follows:
Go help build...-n prints commands used in the process without execution-x executes and prints commands used in the process, note the difference between it and the-n option-work prints the temporary directory path at compile time and retains it at the end. By default, the temporary directory is deleted at the end of compilation. ...
These options also apply to the go run command. Do you think it is similar to the sh command option, you can see that a lot of knowledge in the computer is the same.
Print execution flow
Use the-n option to view the execution flow of go build if the command is not executed, as follows:
$go build-n hello.go## command-line-arguments#mkdir-p $WORK/b001/cat > $WORK/b001/importcfg $WORK/b001/importcfg.link $WORK/b001/importcfg $WORK/b001/importcfg.link
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.