Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building zmq4 for arm architecture #119

Open
jay11ca39 opened this issue Nov 15, 2017 · 7 comments
Open

Building zmq4 for arm architecture #119

jay11ca39 opened this issue Nov 15, 2017 · 7 comments

Comments

@jay11ca39
Copy link

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.

@pebbe
Copy link
Owner

pebbe commented Nov 15, 2017

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.

@jay11ca39
Copy link
Author

jay11ca39 commented Nov 15, 2017

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

@farshidtz
Copy link

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

@peterdeka
Copy link

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

@error10
Copy link

error10 commented Jul 27, 2018

@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.

@marcoreato
Copy link

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.

@farshidtz
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants