[LGTM] link: undefined reference zmq zeromq but lib is specified [SOLVED]

We have a little problem to link libzmq to our project, both libraries are installed:

[2020-10-01 18:01:46] [build] - libzmq3-dev
[2020-10-01 18:01:46] [build] - libzmq5

and “-lzmq” is passed to the linker command but somehow linker can’t find those references

[2020-10-01 18:13:29] [build] libtool: link: g++ -g -O2 -o .libs/tests tests-tests.o -L/opt/out/snapshot/workspace/usr/lib/x86_64-linux-gnu -lhiredis -lswsscommon -lzmq -lpthread …/…/meta/.libs/libsaimetadata.so …/…/meta/.libs/libsaimeta.so ./.libs/libsairedis.so
[2020-10-01 18:13:29] [build] /usr/bin/ld: ./.libs/libsairedis.so: undefined reference to `zmq_connect’

when we compile locally, everything works fine, but fails on lgtm
does anyone have idea what could be the issue here ? we are puzzled :confused:

full log here: https://lgtm.com/projects/g/Azure/sonic-sairedis/logs/rev/pr-70246e0a3c0e100c038821e987190e4d29cd5782/lang:cpp/stage:Build%20merge_3dd7ef4f8057539a0116cc24ced9c067bb72644b

We figured out solution for this, it turned out that order of libs to g++ matters a lot, and “-lzmq” should be specified AFTER lib/source/obj that is actually using it (in Makefile.am)

before:
tests_LDADD = -lhiredis -lswsscommon -lzmq -lpthread (top_srcdir)/meta/libsaimetadata.la (top_srcdir)/meta/libsaimeta.la libsairedis.la

after:
tests_LDADD = -lhiredis -lswsscommon -lpthread (top_srcdir)/meta/libsaimetadata.la (top_srcdir)/meta/libsaimeta.la libsairedis.la -lzmq

in this case libsairedis.la is using zmq apis
hope this helps anyone

1 Like