Home > Article > Backend Development > Does the `-o` output flag of `go build` have any side effects?
#php editor Xinyi will answer a question about the `go build` command in this article, that is, whether the `-o` output flag has any side effects. When using the `go build` command to compile a Go language program, we can specify the name of the output file through the `-o` flag. So, will this flag have any side effects on source code or other files? Next, we will analyze this issue in detail.
Documentation page from go build
:
The -o flag forces build to write the resulting executable or object to the named output file or directory, instead of the default behavior described in the last two paragraphs. If the named output is an existing directory or ends with a slash or backslash, then any resulting executables will be written to that directory.
But the build process I encountered was essentially:
go build -o foo src/ mv foo bar
Is there a reason for doing this that I can't find in the documentation? For example. Does it set the linker symbol name to foo
or something similar? Or is this just a quirk I can safely ignore?
By looking at the checksums of binaries generated by go build
with the same source and different -o
flags, these files Absolutely the same. So there are no side effects.
The above is the detailed content of Does the `-o` output flag of `go build` have any side effects?. For more information, please follow other related articles on the PHP Chinese website!