Closed paulbdavis closed 8 years ago
zmq4 is a binding for the C library ZeroMQ. You need CGO enabled.
Just FYI, I was able to get a static binary by doing the following
CGO_CPPFLAGS="-I/usr/include" \
CGO_LDFLAGS="-L/usr/lib -L/usr/lib/z86_64-linux-gnu -lzmq -lpthread -lsodium -lrt -lstdc++ -lm -lc -lgcc" \
go get --ldflags '-extldflags "-static"' -a myapp/usingzmq4
I know lots of people like using static binaries for deployment. Not sure if this info is helpful to you or others
For searchability golang go static compile zeromq zmq zmq4
Thank you for the answer. This was on my todo list.
@aletheia7 You may need to adjust the paths depending on what you are using to compile. The above works inside the golang
docker container in which I manually compiled zeromq 4.1.3 (installing it from debian jessie gives 4.0.1)
This may be useful too in some cases:
http://statifier.sourceforge.net/
https://groups.google.com/forum/m/#!topic/golang-nuts/7YH5CseB4pc
I could get a static binary like this:
PKG_CONFIG_PATH=/my/opt/zeromq-4.1.3/lib/pkgconfig \
CGO_LDFLAGS="-L/my/opt/libsodium-1.0.3/lib -lsodium -lstdc++ -lrt" \
go build -v --ldflags '-extldflags "-static"' -a program.go
But first I had to install ZeroMQ without libnorm, because there is no static version of that library.
If you were to build it statically, where would this not work For example, if I build on Ubuntu 16.04 and try to deploy on CentOS 6, would that be ok? Would it just work on any linux amd64 distro?
@pebbe,
A static norm build of the norm library can be built, but it is not built by the waf
script.
Steps to build libnorm.a
cd <norm source>
waf configure
waf
cd makefiles
make -f Makefile.linux
# choose the Makefile.* for your platform.cd ..
ls -l lib
# libnorm.a should be present.Linking libnorm.a requires libprotokit.a under
Use libprotokit, not libprotolib.
@pebbe, could you say, what's required to statically build zmq4 these days?
I get errors like this, tried everything already
I have an app that uses github.com/pebbe/zmq4 v1.2.8 . I made a branch. I changed zmq4.go .
/*
#cgo !windows pkg-config: libzmq
/*
#cgo !windows CPPFLAGS: -I/usr/local/include
#cgo !windows LDFLAGS: -L/usr/local/lib -L/usr/lib/i386-linux-gnu -lzmq -lpthread -lsodium -lrt -lstdc++ -lm -lc -lgcc
configure
and only build statically and use an install prefix of /usr/local (or adjust /usr/loca/... above).configure
. It should use the static libsodium.Be sure you have previously removed libsodium and libzmq packages so that you do not have multiple builds.
I am trying to build a static binary and I get the following error