简体   繁体   English

Go:如何运行file.go工作

[英]Go: How does go run file.go work

The commands go build and go install compile the files into binaries. 命令go build并运行go install将文件编译为二进制文件。 Does go run compile or interpret the file? go run编译还是解释文件? I couldn't find explanations online and may have missed it. 我在网上找不到解释,可能错过了。 Appreciate pointers. 欣赏指针。 Thanks! 谢谢!

它或多或少相当于运行go build X.go -o /tmp/random-tmp-folder/exe && /tmp/random-tmp-folder/exe

The go run command compiles and runs a main package comprised of the .go files specified on the command line. go run命令编译并运行由命令行上指定的.go文件组成的主程序包。 The command is compiled to a temporary folder. 该命令被编译为临时文件夹。

The go build and go install examine the files in the directory to determine which .go files are included in the main package. go buildgo install检查目录中的文件,以确定主包中包含哪些.go文件。

与在执行时创建和解释bytcode的java不同,go创建一个依赖于正在使用的机器的可执行文件,如c,c ++。

Command go run performs project's building under the hood (so yes it builds project) 命令go run在引擎盖下执行项目的构建(所以它是构建项目)
and with flag --work ( go run --work main.go ) you can see the location of temporary build files. 并使用flag --work( go run --work main.go ),您可以看到临时构建文件的位置。

Also in official documentation ( go1.11 ) you can find: 同样在官方文档( go1.11 )中,您可以找到:

go run - compiles and runs the named main Go package. go run - 编译并运行命名的主Go包。

go build - compiles the packages named by the import paths, along with their dependencies, but it does not install the results. go build - 编译导入路径命名的包及其依赖项,但不安装结果。

go install - compiles and installs the packages named by the import paths. go install - 编译并安装导入路径命名的包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM