我正在尝试使用go-qml或gotk3来构建一个可以在OS X下运行的非常简单的桌面应用程序。但是,当我尝试使用go get
安装任一库时,它将尝试构建i386并跳过针对x86_64构建的库。我可以尝试获得这些库的32位版本,但我更愿意为64位构建。我如何指示去做?
错误后面的警告是这样的:
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
答案 0 :(得分:4)
将环境变量GOARCH
设置为值amd64
。这指示go
命令为amd64
生成文件。 GOARCH
的其他有效值为386
和arm
。
答案 1 :(得分:0)
Go 编译器支持以下指令集:
(来自:Introduction | 从源代码安装 Go | 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
(* snip *)
为 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 .