英文:
How do I make `go get` to build against x86_64 instead of i386
问题
我正在尝试使用go-qml或gotk3构建一个非常简单的桌面应用程序,可以在OS X下运行。然而,当我尝试使用go get
安装这两个库时,它会尝试为i386构建,并跳过针对x86_64构建的库。我可以尝试获取这些库的32位版本,但我更喜欢为64位构建。我该如何指示go get这样做?
后面跟着错误的警告看起来像这样:
go get gopkg.in/qml.v1
# gopkg.in/qml.v1
ld: warning: ld: warning: ld: warning: ignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgets, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgetsignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGui, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGuiignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick
英文:
I am trying to use either go-qml or gotk3 to build a very simple desktop app that can run under OS X. However when I try to use go get
to install either library, it will try to build for i386 and skip the libraries that were build against x86_64. I could try to get the 32 bit version of those libraries, but I would prefer to build for 64bit. How do I instruct go get to do so?
The warnings that are followed by errors look lie this:
go get gopkg.in/qml.v1
# gopkg.in/qml.v1
ld: warning: ld: warning: ld: warning: ignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgets, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgetsignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGui, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGuiignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick
答案1
得分: 10
将环境变量GOARCH
设置为值amd64
。这将指示go
命令生成amd64
的文件。GOARCH
的其他有效值包括386
和arm
。
英文:
Set the environment variable GOARCH
to the value amd64
. This instructs the go
command to generate files for amd64
. Other valid values for GOARCH
are 386
and arm
.
答案2
得分: 1
F.Y.I.
> Go编译器支持以下指令集:
>
> - amd64, 386
> - x86指令集,64位和32位。
> - arm64, arm
> - ARM指令集,64位(AArch64)和32位。
> - mips64, mips64le, mips, mipsle
> - MIPS指令集,大端和小端,64位和32位。
> - ppc64, ppc64le
> - 64位PowerPC指令集,大端和小端。
> - riscv64
> - 64位RISC-V指令集。
> - s390x
> - IBM z/Architecture。
> - wasm
> - WebAssembly。
>
>(来源:Introduction | Installing Go from source | Doc @ golang.org)
另外,你可以使用 go tool dist list
命令来检查你的机器上可用的架构。
$ go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
(* 省略 *)
要构建macOS(Intel/ARM64)的静态二进制文件,可以按照以下方式进行。我假设 GOOS="darwin" GOARCH="arm64"
的组合适用于 M1
架构。
MyVar="foo"
CGO_ENABLED=0 \
GOOS="darwin" \
GOARCH="amd64" \
GOARM="" \
go build \
-ldflags="-s -w -extldflags \"-static\" -X 'main.myVar=${MyVar}'" \
-o="/path/to/export/bin/myApp" \
"/path/to/main.go"
要编译适用于ARM v6的Linux,例如RaspberryPi Zero W,可以使用以下组合。
$ CGO_ENABLED=0 GOOS="linux" GOARCH="arm" GOARM="6" go build .
英文:
F.Y.I.
> The Go compilers support the following instruction sets:
>
> - amd64, 386
> - The x86 instruction set, 64- and 32-bit.
> - arm64, arm
> - The ARM instruction set, 64-bit (AArch64) and 32-bit.
> - mips64, mips64le, mips, mipsle
> - The MIPS instruction set, big- and little-endian, 64- and 32-bit.
> - ppc64, ppc64le
> - The 64-bit PowerPC instruction set, big- and little-endian.
> - riscv64
> - The 64-bit RISC-V instruction set.
> - s390x
> - The IBM z/Architecture.
> - wasm
> - WebAssembly.
>
> (from: Introduction | Installing Go from source | Doc @ golang.org)
Also, you can go tool dist list
to check the available architectures to build in your machine.
$ go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
(* snip *)
To build a static binary for macOS (Intel/ARM64) would be as below. In this manner, I suppose GOOS="darwin" GOARCH="arm64"
combination will be for M1
architecture.
MyVar="foo"
CGO_ENABLED=0 \
GOOS="darwin" \
GOARCH="amd64" \
GOARM="" \
go build \
-ldflags="-s -w -extldflags \"-static\" -X 'main.myVar=${MyVar}'" \
-o="/path/to/export/bin/myApp" \
"/path/to/main.go"
To compile for Linux on ARM v6, such as RaspberryPi Zero W, the combination would be as below.
$ CGO_ENABLED=0 GOOS="linux" GOARCH="arm" GOARM="6" go build .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论