英文:
What happens to the executable when using the run command in the go compiler?
问题
使用go build myprogram.go
命令会生成一个可执行文件,这在使用编译器时我很熟悉。
然而,使用go run myprogram.go
命令不会创建任何可执行文件,但仍然会运行程序。
这是如何工作的呢?是先创建可执行文件然后再删除,还是像解释器一样直接运行代码?
英文:
Using the go build myprogam.go
produces an executable file, which is what I'm familiar with when working with compilers.
However, using go run myprogram.go
doesn't create any executable files and still runs the program.
How exactly does this work, is the executable created and then deleted or does it run the code like an interpreter would?
答案1
得分: 1
一个临时的可执行文件被创建。
对于go test也是一样的。
关于go test
的文档
该包在一个临时目录中构建,以免干扰非测试安装。
你也可以运行fmt.Println(os.Args[0])
来查看正在创建的可执行文件。
英文:
A temporary executable is created.
The same is the case for go test.
Documentation on go test
The package is built in a temporary directory so it does not interfere with the non-test installation.
You can also run fmt.Println(os.Args[0])
to see the executable file that is being created.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论