Skip to content

Commit 9b69314

Browse files
committed
go: 跨平台编译
1 parent 1f19c4f commit 9b69314

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go-note/web.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,18 @@ Go 断点调试器dlv
310310
311311
- https://yq.aliyun.com/articles/57578
312312

313+
Go 跨平台编译
314+
---------------------------------------------------------------
315+
用 Go 你可以选择自己喜欢的操作系统开发,并跨平台编译程序要发布平台的可执行程序即可。
316+
Go 通过两个环境变量控制跨平台编译:
317+
318+
- GOOS: 代表要编译的目标操作系统,常见的有 Linux, Windows, Darwin 等
319+
- GOARCH: 代表要编译的目标处理器架构,常见的有 386, AMD64, ARM64 等
320+
321+
比如现在在用 macOS AMD64 开发,但是想要编译出 Linux AMD64 的可执行程序,只需要执行:
322+
323+
`GOOS=linux GOARCH=amd64 go build main.go`
324+
313325
Go Debug 调试工具
314326
---------------------------------------------------------------
315327
- go-spew: 用来打印一些复杂结构方便调试 https://github.com/davecgh/go-spew

0 commit comments

Comments
 (0)