Centos下使用epel源安装:
1 | yum install golang |
Centos/Linux下源码安装golang:
1 2 3 4 5 6 7 8 | wget https: //dl .google.com /go/go1 .13.4.linux-amd64. tar .gz tar -C /usr/local -xzf go*linux-amd64. tar .gz mkdir $HOME /go echo 'export GOROOT=/usr/local/go' >> ~/.bashrc echo 'export GOPATH=$HOME/go' >> ~/.bashrc echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc echo 'export GO111MODULE=auto' >> ~/.bashrc source $HOME/.bashrc |
安装go get工具:
1 | yum install mercurial git bzr subversion |
Windows下安装:
设置环境变量:
1 2 3 4 5 6 | setx GOOS windows setx GOARCH amd64 setx GOROOT "D:\Program Files\go" setx GOBIN "%GOROOT%\bin" setx GO111MODULE auto setx PATH %PATH% ; "D:\Program Files\go\bin" |
交叉编译:
1 2 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go |
减小编译生成文件大小:
1 | go build -ldflags "-s -w" |
感谢,一点不啰嗦,还很管用!
请教一下
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
stat main.go: no such file or directory
这个是为什么了?
交叉编译的作用是?