如何为Go构建8g和6g Go编译器?

huangapple go评论91阅读模式
英文:

How do you build the 8g and 6g Go compilers for Go

问题

我正在编写一款软件,将在Windows、Mac和Linux系统上广泛部署,使用x86和x86-64架构。每当我在我的Mac和Linux系统上设置go编译器时,我只能得到6g版本。在Windows上,我只使用预编译的实验性二进制文件,使用8g版本。

当我开始设置构建服务器时,我假设我也需要构建8g版本,以便能够生成32位版本。如何设置8g版本,特别是在Mac上(因为它们可能是x86或x64,取决于其年龄)?

英文:

I'm writing software that will be somewhat widely deployed amongst Windows, Mac, and Linux systems on x86 and x86-64 architectures. Whenever I set up the go compiler on my Mac and Linux systems I only ever get 6g built. On Windows I just use the pre-built experimental binaries, which uses 8g.

When I get around to setting up build servers, I assume I need to also build 8g so I can produce 32 bit builds as well. How do I set up 8g, in particular on a Mac (since they can be x86 or x64 depending on how old they are)?

答案1

得分: 3

你必须将环境变量GOARCH设置为386,而不是由all.bash构建脚本自动选择的amd64。有关详细信息,请参阅Go文档中的环境变量部分。

英文:

You have to set the environment variable GOARCH to 386 instead of probably automatically chosen amd64 by the all.bash build script. See environment variables in Go documentation for details.

答案2

得分: 1

如另一个帖子所说,使用GOARCH。他没有说的是你不需要多个目录。

运行all.bash两次,使用相同的GOROOT

GOARCH=amd64 ./all.bash
GOARCH=386 ./all.bash

当你使用gomake构建某个东西时,如果默认的GOARCH不适合你,可以设置GOARCH

GOARCH=386 gomake

不幸的是,goinstall目前还不支持GOARCH

请注意,gc编译器总是进行交叉编译。一旦你拥有所需架构的编译器,设置GOOS并在$GOROOT/src/pkg中构建软件包,然后你应该能够构建针对任何操作系统或架构的软件。

GOARCH=386 GOOS=windows gomake
英文:

As another poster said, use GOARCH. What he didn't say is that you don't need multiple directories.

Run all.bash twice, same GOROOT:

GOARCH=amd64 ./all.bash
GOARCH=386 ./all.bash

When you build something with gomake set up GOARCH if the default doesn't suit you

GOARCH=386 gomake

Unfortunately goinstall doesn't honor GOARCH yet.

Notice that gc compilers are always cross compiling. Once you have the compilers for the architecture you need, set GOOS and build the packages in $GOROOT/src/pkg, then you should be able to build your software targeting any operating system or architecture.

GOARCH=386 GOOS=windows gomake

huangapple
  • 本文由 发表于 2011年10月17日 02:47:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/7786492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定