Loading... # 0x01 使用 CGO 编译需要用大量的依赖库,市面上能找到的基本都是基于 [Ubuntu 的交叉编译镜像](https://github.com/gythialy/golang-cross) 要用 CentOS 为基础的镜像进行编译只能自己找相关依赖了。下面均为 linux/amd64 的编译参数。 ## 编译 linux/386 ```bash # go env GOOS=linux GOARCH=386 CC=gcc CXX=g++ # BuildRequires $ yum install libstdc++-*.i686 $ yum install glibc-*.i686 $ yum install libgcc.i686 ``` ## 编译 windows/386 ```bash # go env GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-gcc++ # BuildRequires $ yum install mingw32-gcc $ yum install mingw32-gcc-c++ $ yum install mingw-binutils-generic $ yum install mingw-filesystem-base ``` ## 编译 windows/amd64 ```bash # go env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ # BuildRequires $ yum install mingw64-gcc $ yum install mingw64-gcc-c++ $ yum install mingw-binutils-generic $ yum install mingw-filesystem-base ``` # Reference [Cross-Compiling Golang (CGO) Projects](https://dh1tw.de/2019/12/cross-compiling-golang-cgo-projects/) [32-bit life support: Cross-compiling with GCC](https://opensource.com/article/19/7/cross-compiling-gcc) [golang-cross](https://github.com/gythialy/golang-cross) [x86_64 Linux Error: gnu/stubs-32.h Missing Error and Solution](https://www.cyberciti.biz/faq/x86_64-linux-error-gnustub-32h-missing-error-and-solution/) 最后修改:2022 年 09 月 27 日 02 : 43 PM © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 赞赏作者 支付宝微信