zeromq / zmqpp

0mq 'highlevel' C++ bindings
http://zeromq.github.io/zmqpp
Mozilla Public License 2.0
438 stars 195 forks source link

Linking with libzmqpp fails on windows / mingw-w64. #192

Closed Smasherr closed 7 years ago

Smasherr commented 7 years ago

I am trying to create a proxy object in my code:

zmqpp::socket dealer(ctx, zmqpp::socket_type::xrequest);
zmqpp::socket router(ctx, zmqpp::socket_type::xreply);
router.bind("tcp://*:1234");
dealer.bind("inproc://workers");
zmqpp::proxy(router, dealer);

That linking error message appears: undefined reference to 'zmqpp::proxy::proxy(zmqpp::socket&, zmqpp::socket&)'

If I change the proxy class definition as following:

class __declspec(dllexport) proxy

and rebuild zmpqq, my binary gets linked well.

I am using the latest sources of libzmq and zmpqq pulled from git on msys2 with mingw-w64, cmake 3.8 and gcc 6.3.0.

bluca commented 7 years ago

What's missing is the ZMQPP_EXPORT attribute, eg:

class proxy

should probably be

class ZMQPP_EXPORT proxy

https://github.com/zeromq/zmqpp/blob/develop/src/zmqpp/proxy.hpp#L27

Since it affects you, could you please test it and send a PR if this works for you? Thanks!

Smasherr commented 7 years ago

I already tried it and I should have mentioned that, sorry. With ZMQPP_EXPORT i get another error: undefined reference to '__imp__ZN5zmqpp5proxyC1ERNS_6socketES2_'. This is because ZMQPP_EXPORT evaluates to __declspec(dllimport) for me for some reason, my IDE reveals me the following view on zmqpp_export.h, if I request a declaration of this ZMQPP_EXPORT: zmqpp_export.h

bluca commented 7 years ago

all classes use that macro, not sure what's happening with your IDE, I'm not a windows expert sorry, maybe someone else can help

Smasherr commented 7 years ago

The IDE only shows that zmqpp_EXPORTS is not currently defined in my environment. I realized this is irrelevant. zmqpp_EXPORTS should be set during compile time. I enabled the verbosity of makefile to check if that option is set during compilation of proxy.cpp. It was the case (see line 473). To my surprise adding ZMQPP_EXPORT to proxy class and repeated rebuilding of ZMQPP made my code link successfully this time.

So I'll send a PR, thanks for your support!

bluca commented 7 years ago

Fixed by https://github.com/zeromq/zmqpp/pull/193