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

deyen · · 4557 次点击
你需要补下编译相关的知识。gcc/g++是c/c++的编译工具。编译windows下能运行的需要GNU on Windows。MinGW就是这个东西。而你又要Linux下交叉编译windows的,所以需要在linux使用mingw而不是gcc。CC这个环境变量就是制定c的编译工具。还有个CXX指定c++编译工具
#13
更多评论
首先,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