Go: How does go run file.go work

前端 未结 4 1751
一个人的身影
一个人的身影 2021-01-07 19:08

The commands go build and go install compile the files into binaries. Does go run compile or interpret the file? I couldn\'t find expl

相关标签:
4条回答
  • 2021-01-07 19:36

    It's more or less the equivalent of running go build X.go -o /tmp/random-tmp-folder/exe && /tmp/random-tmp-folder/exe

    0 讨论(0)
  • 2021-01-07 19:43

    Unlike in java, where the bytcode is created and interpreted at the execution time, go creates an executable file that is dependent on the machine being used,like in c, c++.

    0 讨论(0)
  • 2021-01-07 19:44

    Command go run performs project's building under the hood (so yes it builds project)
    and with flag --work (go run --work main.go) you can see the location of temporary build files.

    Also in official documentation (go1.11) you can find:

    go run - compiles and runs the named main Go package.

    go build - compiles the packages named by the import paths, along with their dependencies, but it does not install the results.

    go install - compiles and installs the packages named by the import paths.

    0 讨论(0)
  • 2021-01-07 19:47

    The go run command compiles and runs a main package comprised of the .go files specified on the command line. 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.

    0 讨论(0)
提交回复
热议问题