Does the `-o` output flag of `go build` have any side effects?

王林
Release: 2024-02-11 17:20:08
forward
960 people have browsed it

`go build` 的输出标志 `-o` 有副作用吗?

#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.

Question content

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.
Copy after login

But the build process I encountered was essentially:

go build -o foo src/
mv foo bar
Copy after login

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?

Workaround

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!