[zeromq-dev] Example for building against ZMQ with CMake + UDP Multicast Support

Luca Boccassi luca.boccassi at gmail.com
Tue Jan 10 23:04:38 CET 2017


On 10 January 2017 at 22:01, Luca Boccassi <luca.boccassi at gmail.com> wrote:
> On 10 January 2017 at 21:33, Stephan Opfer <opfer at vs.uni-kassel.de> wrote:
>> On 10.01.2017 22:20, Luca Boccassi wrote:
>>>
>>> luca at luca-desktop:/tmp$ apt-cache policy libzmq3-dev
>>> libzmq3-dev:
>>>    Installed: 1483950852.598befc
>>>    Candidate: 1483950852.598befc
>>>    Version table:
>>>   *** 1483950852.598befc 0
>>>
>>> 500http://download.opensuse.org/repositories/home:/zeromq:/git-draft/Debian_8.0/
>>> ./ Packages
>>>          100 /var/lib/dpkg/status
>>>       4.2.1-2 0
>>>          103http://httpredir.debian.org/debian/  sid/main amd64 Packages
>>>       4.2.0-2 0
>>>          104http://httpredir.debian.org/debian/  stretch/main amd64
>>> Packages
>>>       4.0.5+dfsg-2+deb8u1 0
>>>          500http://httpredir.debian.org/debian/  jessie/main amd64
>>> Packages
>>>          500http://security.debian.org/  jessie/updates/main amd64
>>> Packages
>>> luca at luca-desktop:/tmp$ g++ `pkg-config --libs --cflags libzmq`
>>> Discovery.cpp -o test
>>> luca at luca-desktop:/tmp$ ./test
>>>
>>>
>>> Builds just fine (binary runs and never exits not sure if that's
>>> intended). I am honestly not sure why your linker is being picky. This
>>> is on Debian 8 with gcc 4.9.2
>>
>> $ apt-cache policy libzmq3-dev
>> libzmq3-dev:
>>   Installed: 1483950852.598befc
>>   Candidate: 1483950852.598befc
>>   Version table:
>>  *** 1483950852.598befc 500
>>         500
>> http://download.opensuse.org/repositories/home:/zeromq:/git-draft/xUbuntu_16.04
>> ./ Packages
>>         100 /var/lib/dpkg/status
>>      4.1.4-7 500
>>         500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
>>
>> A little bit strang, that I don't see a Version named 4.2.x like you have.
>> Nevertheless, this would only create a lack of the new UDP Multicast
>> feature, but my linker complains about standard functions like
>> zmq_ctx_new...
>>
>> I am using g++ version 5.4.0 on Ubuntu 16.04 LTS. I further guaranteed that
>> there is only one libzmq.
>> Its location is: /usr/lib/x86_64-linux-gnu/libzmq.so.5.1.2
>> And I checked that the wanted symbol is in there with: readelf -Ws
>> /usr/lib/x86_64-linux-gnu/libzmq.so.5.1.2
>>
>> Normally under this circumstances problems like mismatching architecture of
>> the .so is the case, but I can't see any hints for that.
>
> Uh, I have an Ubuntu 16.04 machine around and I can indeed reproduce
> the same problem. This is weird. Investigating...

Gaaaah. Why, gcc, why!!

You need to pass the source file BEFORE the linker flags.

This works:

g++ Discovery.cpp `pkg-config --libs --cflags libzmq` -o test

This fails:

g++ `pkg-config --libs --cflags libzmq` Discovery.cpp -o test

Unbelievable. And I'm sure I've tripped over this a few times already...



More information about the zeromq-dev mailing list