zmq4: Can't compile on Alpine Linux

I have a Golang application that utilizes pebbe/zmq4 and I’d love to be able to run it in Alpine Linux due to the much smaller container size. However, I get the following error:

apk update
apk install gcc pkgconfig zeromq-dev
go run main.go
# github.com/pebbe/zmq4
In file included from /go/src/github.com/pebbe/zmq4/ctxoptions_unix.go:6:0:
/usr/include/zmq.h:46:19: fatal error: errno.h: No such file or directory
compilation terminated.

I’m using the golang:1.5-alpine container available on Docker Hub.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

In case someone has this issue in the future, here’s the needed commands:

RUN apk add --no-cache zeromq-dev musl-dev pkgconfig alpine-sdk libsodium-dev
RUN CGO_LDFLAGS="$CGO_LDFLAGS -lstdc++ -lm -lsodium" \
  CGO_ENABLED=1 \
  GOOS=linux \
  go build -v -a --ldflags '-extldflags "-static" -v'

This works:

~ docker run -i -t blang/golang-alpine sh
/go # apk update
/go # apk add gcc pkgconfig zeromq-dev
/go # apk add git musl-dev
/go # go get github.com/pebbe/zmq4
/go # go test -v github.com/pebbe/zmq4

Result:

PASS
ok      github.com/pebbe/zmq4   11.619s

@manveru Thank you very much For static link, I also need to add libzmq-static libsodium-static

Thank you @manveru I had the error: ImportError: Error loading shared library libzmq.so.5: No such file or directory (needed by /usr/local/lib/python3.6/site-packages/zmq/backend/cython/error.cpython-36m-x86_64-linux-gnu.so) while trying to install zeromq-dev (and also libzmq) with the RUN command in a Dockerfile with alpine3.6. Adding only the first RUN command that you suggested already fixed the problem. Thanks!