首頁  >  文章  >  後端開發  >  `go build` 的輸出標誌 `-o` 有副作用嗎?

`go build` 的輸出標誌 `-o` 有副作用嗎?

王林
王林轉載
2024-02-11 17:20:08935瀏覽

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

php小編新一在本文中將為大家解答一個關於 `go build` 指令的問題,即 `-o` 輸出標誌是否有副作用。在使用 `go build` 指令編譯 Go 語言程式時,我們可以透過 `-o` 標誌指定輸出檔的名稱。那麼,這個標誌會不會對原始碼或其他檔案產生任何副作用呢?接下來,我們將對這個問題進行詳細的解析。

問題內容

來自 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.

但是我遇到的建置過程本質上是:

go build -o foo src/
mv foo bar

是否有我在文件中找不到的這樣做的原因?例如。它是否將連結器符號名稱設定為 foo 或類似的名稱?或者這只是一個我可以放心忽略的怪癖?

解決方法

透過查看具有相同來源和不同-o 標誌的go build 產生的二進位檔案的校驗和,這些文件絕對相同。所以沒有副作用。

以上是`go build` 的輸出標誌 `-o` 有副作用嗎?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除