Golang 編譯相關
env GOOS=linux GOARCH=amd64 go build -o {executable name} {main function entry file path}
註:在使用 Git bash 的情況下
另外如遇到執行環境版本為 Linux 下無法支援 C 函式庫的調用錯誤訊息(錯誤訊息如下):
./{executable name}: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./{executable name})
./{executable name}: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./{executable name})
可在編譯時的環境變數再加上 CGO_ENABLED=0
以禁用 C 代碼或是函式庫。
env GOOS=linux CGO_ENABLED=0 go build -o {executable name} {main function entry file path}
[補充資料]
如果想要得知編譯後的執行檔當初是由哪個 Golang 版本編譯出來的,可以使用以下方式檢查執行檔編譯時期附加的 metadata:
# 取得 Golang 版本號
strings {executable name} | grep "^go[0-9]\.[\.|0-9]*"
# 取得當下版本控制提交雜湊 ID
strings {executable name} | grep "vcs.revision"
* 可切換到指定分支並使用 git rev-parse HEAD
檢查 commit hash 是否一致
# 指定鏈接器標誌的選項;允許傳遞參數給鏈接器,通常用於指定版本訊息或是初始化執行檔設定,以下範例為指定執行檔版本號
go build -ldflags '-X main.version=1.0.0'
# 指定編譯器標誌的選項;允許傳遞參數給編譯器,通常用於欲進行優化作業的詳細資訊查看,以下範例為查看變數逃逸分析 (heap & stack)
go build -gcflags '-m -l'
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information