golang交叉编译上遇到的问题!

deyen · · 4557 次点击
ubuntu上的例子: 先装好 ``` mingw-w64 libz-mingw-w64 ``` 然后写这样一个脚本(用于编译win32): ``` #!/bin/sh export CGO_ENABLED=1 export GOOS=windows export GOARCH=386 export CC=i686-w64-mingw32-gcc export CXX=i686-w64-mingw32-g++ go build -ldflags '-s -w -H=windowsgui' ```
#20
更多评论
首先,amd64 linux 编译到 amd64 windows 的程序,命令应该是: ``` CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go ``` 其次,fyne.io/fyne 这个库应该用了 CGO,需要安装响应的 gcc,指定 gcc 才能编译,例如: ``` CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-xxx-gcc CGO_LDFLAGS="-static" go build main.go ```
#1
按照你的提示去做,出现以下代码。 ``` $ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-xxx-gcc CGO_LDFLAGS="-static" go build main.go # runtime/cgo cgo: C compiler "x86_64-xxx-gcc" not found: exec: "x86_64-xxx-gcc": executable file not found in $PATH ``` (怎么我看网上有说法说cgo不支持交叉编译,所以CGO_ENABLED=0来着😂😂)
#2