0
Golang交叉编译
source link: https://neilliu9891.github.io/2020/10/golang%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Golang 交叉编译
由于自己的开发环境是Linux开发环境,但自己编写的工具需要运行在windows的环境中,所以需要用到交叉编译工具.
Ubuntu下编译windows 程序
参考: > https://studygolang.com/articles/8167
- Install gcc-mingw-w64:gcc编译器
apt-get install gcc-mingw-w64
- Cross platform compiler
64bit
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -o main.exe main.go
32bit
env CGO_ENABLED=1 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build -o main.exe main.go
- Common Error
Q:gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?
A:CGO_ENABLED=1但是未指定CC编译器
Q:运行时出错(error="Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work.)
A:CGO_ENABLED未设置成1
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK