gpt4 book ai didi

linux - Golang : How to cross compile on Linux for Windows

转载 作者:IT老高 更新时间:2023-10-28 13:08:01 28 4
gpt4 key购买 nike

如何在 Linux 上交叉编译 Go 项目以生成在 Windows 上运行的可执行文件?

最佳答案

要从 Linux 构建到 Windows,您需要将环境变量 GOOS 设置为 Windows 并将 GOARCH 设置为 amd64.

在 Bash 或 ZSH 上:

% GOOS=windows GOARCH=amd64 go build

如果你的包需要 CGO 那么你需要使用 mingw-w64 编译器:

sudo apt-get install gcc-multilib
sudo apt-get install gcc-mingw-w64

GOOS=windows GOARCH=386 \
CGO_ENABLED=1 CXX=i686-w64-mingw32-g++ CC=i686-w64-mingw32-gcc \
go build

关于linux - Golang : How to cross compile on Linux for Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41566495/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com