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

deyen · · 4787 次点击
运行后是这样的,linux上安装x86_64-w64-mingw64-gcc是要哪个包?包名叫什么?我用`yum search mingw64`一大堆东西 ``` $ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw64-gcc CGO_LDFLAGS="-static" go build main.go # runtime/cgo cgo: C compiler "x86_64-w64-mingw64-gcc" not found: exec: "x86_64-w64-mingw64-gcc": executable file not found in $PATH ```
#11
更多评论
首先,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