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
"AMD64" is the name chosen by AMD for their 64-bit extension to the Intel x86 instruction set. Before release, it was called "x86-64" or "x86_64", and some distributions still use these names.
The go build command compiles the packages, along with their dependencies, but it doesn't install the results. The go install command compiles and installs the packages.
You can set either the GOOS or GOARCH environment variables to build for a different platform using go build . If you are not using a Windows system, build a windows binary of app by setting the GOOS environment variable to windows when running the go build command: GOOS=windows go build.
GOOS refers to the operating system (Linux, Windows, BSD, etc.), while GOARCH refers to the architecture to build for. $ env GOOS=linux GOARCH=arm64 go build -o prepnode_arm64.
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
.
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With