zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.93k stars 757 forks source link

Undefined references when using libzmq.so.5.2.4 #561

Open null0x opened 2 years ago

null0x commented 2 years ago

Short: To build the provided unit tests it necessary to install at least libzmq.so.5.2.5. However, the package libzmq3-dev and the dependent package libzmq5, that can be installed using apt, only provide libzmq.so.5.2.4.

Long: I am trying to build the provided unit tests of a freshly cloned copy of this repository. For this purpose, I first installed the libzmq3-dev package to get the libzmq.so library on my Ubuntu 20.04 LTS system. The dependent package libzmq5 package contains libzmq.so.5.2.4:

ls /usr/lib/x86_64-linux-gnu | grep zmq
libzmq.a
libzmq.so
libzmq.so.5
libzmq.so.5.2.4

Whenever I call cmake -B build && make -C build -j8, I receive a bunch of linker errors:

/usr/bin/ld: CMakeFiles/unit_tests.dir/message.cpp.o: in function `zmq::message_t::routing_id() const':
message.cpp:(.text._ZNK3zmq9message_t10routing_idEv[_ZNK3zmq9message_t10routing_idEv]+0x18): undefined reference to `zmq_msg_routing_id'
/usr/bin/ld: CMakeFiles/unit_tests.dir/message.cpp.o: in function `zmq::message_t::set_routing_id(unsigned int)':
message.cpp:(.text._ZN3zmq9message_t14set_routing_idEj[_ZN3zmq9message_t14set_routing_idEj]+0x21): undefined reference to `zmq_msg_set_routing_id'

...

The problem is that the installed libzmq.so.5.2.4 does not contain the missing functions: nm -D libzmq.so.5.2.4 | grep "routing_id" returns nothing

The issue can be solved by manually building the most recent zmq version. Then I get libzmq.so.5.2.5 that indeed includes the missing functions:

nm -D libzmq.so.5.2.5 | grep routing_id
00000000000b6270 T zmq_msg_routing_id
...

The outdated system library needs to be manually replaced with libzmq.so.5.2.5. Then everything works fine.

The requirement for zmq version 5.2.5 should be mentioned somewhere. It costs quite a lot time to figure out the problem.

gummif commented 2 years ago

This is probably because the install libzmq is without draft but when building cppzmq the default is to use draft, see ENABLE_DRAFTS in CMakeLists.txt. Try turning it off.

null0x commented 2 years ago

Thank you. But my problem is not that I don't know how to build this project. I just took me some time to find out what zmq version is required. My intention is to make you aware of this and to prevent others from losing time with the same problem.

You could just define the minimum lib version of zmq in CMake.

gummif commented 2 years ago

cppzmq does checks at compile to to see if using draft features, even if using the latest libzmq (without draft) it will result in an error if compiling cppzmq with draft. So it is a matter of compiling both libraries with compatible macro defines.