macos cgo cross compile
记录在macOS上编译Windows和Linux的go程序,带CGO调用C代码,比如go-sqlite3包,已测试通过。
参考链接:
https://www.cnblogs.com/ibgo/p/6489488.html
http://www.mingw-w64.org/doku.php/download/macports
https://github.com/mattn/go-sqlite3/issues/532
https://github.com/mattn/go-sqlite3/issues/372#issuecomment-396863368
https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/
- Windows平台(mingw-w64)
安装编译器:brew install mingw-w64
编译指令:CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -v
- Linux平台(x86_64-linux-musl-gcc)
安装编译器:brew install FiloSottile/musl-cross/musl-cross
编译指令:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CGO_LDFLAGS="-static" go build -a -v
注:
-a:重新编译
-static表示静态连接,没有这个选项,linux上运行报:-bash: ./xxx: /lib/ld-musl-x86_64.so.1: bad ELF interpreter: No such file or directory
————————————————
版权声明:本文为CSDN博主「henly1217」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/henly1217/article/details/102551251