zmq4 icon indicating copy to clipboard operation
zmq4 copied to clipboard

Building zmq4 for arm architecture

Open jay11ca39 opened this issue 8 years ago • 7 comments

Hi @pebbe ,

I am trying to build my GO SDK which is written on the top of zmq4 for ARM architecture. But I am getting the following error:

$ GOOS=linux GOARCH=arm go build
# github.com/pebbe/zmq4
../../github.com/pebbe/zmq4/reactor.go:10:4: undefined: State
../../github.com/pebbe/zmq4/reactor.go:11:9: undefined: State

Also I tried for: GOOS=linux GOARCH=arm64 go build

But I got the same error.

Machine Info: Linux 14.04 [64-bit] GO version : go1.9 linux/amd64

Can you please let me know whether it is possible to build zmq4 for arm architecture. and what is the pre-requisites to do so.

jay11ca39 avatar Nov 15 '17 10:11 jay11ca39

You need CGO enabled. Run this:

GOOS=linux GOARCH=arm go env

If is says CGO_ENABLED="0", you can't build zmq4 for this arch. You may try to build zmq4 on ARM itself.

pebbe avatar Nov 15 '17 10:11 pebbe

Yes, I am getting: CGO_ENABLED="0" There is no way to do cross-compiling for zmq4 for arm arch ?

jay11ca39 avatar Nov 15 '17 10:11 jay11ca39

I tried enabling CGO but got different errors:

$ GOOS=linux GOARCH=arm go install ...
# .../vendor/github.com/pebbe/zmq4
src/.../vendor/github.com/pebbe/zmq4/reactor.go:10:4: undefined: State
src/.../vendor/github.com/pebbe/zmq4/reactor.go:11:9: undefined: State
$ GOOS=linux GOARCH=arm CGO_ENABLED=1 go install ...
# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb' [-Werror,-Wunused-command-line-argument]
$ GOOS=linux GOARCH=arm CGO_ENABLED=1 CGO_CFLAGS="-Wno-unused-command-line-argument" go install ...
# runtime/cgo
In file included from _cgo_export.c:3:
cgo-gcc-export-header-prolog:25:55: error: '_check_for_32_bit_pointer_matching_GoInt' declared as an array with a negative size

farshidtz avatar May 24 '18 10:05 farshidtz

Does anybody have a solution for this? Trying to avoid compling directly on ARM,

peterdeka avatar Jul 09 '18 08:07 peterdeka

@peterdeka You'd need to install a C cross-compiler. The reason this fails is that zmq4 is a wrapper over the C ZeroMQ library, which must also be compiled. Setting up a C cross-compiler is a serious pain and it would generally be easier to compile natively on ARM.

error10 avatar Jul 27 '18 20:07 error10

I have found a solution that might help: indeed a cross-compiler for the target architecture is needed, and you should have also cross-compiled zmq before.

I am currently using this script to compile (my target architecture is ARMv7):

#!/bin/bash

ARM_PREFIX="arm-linux-gnueabihf-" 

TOOLCHAIN_PATH="/path/to/your/toolchain"

CC="${TOOLCHAIN_PATH}/bin/${ARM_PREFIX}gcc" \
CFLAGS="-march=armv7-a -mfpu=neon" \
GOOS=linux \
GOARCH=arm \
GOARM=7 \
CGO_ENABLED=1 \
PKG_CONFIG_PATH="${TOOLCHAIN_PATH}/lib/pkgconfig" \
go build

Just be careful that the paths defined for pkg-config to find in ${TOOLCHAIN_PATH}/lib/pkg-config/libzmq.pc are correct.

marcoreato avatar Dec 10 '18 09:12 marcoreato

I can confirm that @marcoreato's solution works. I've created a docker image for armv7 cross compilation with static linking. Source is here: https://github.com/farshidtz/zmq4-arm

farshidtz avatar Mar 19 '19 13:03 farshidtz