zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.45k stars 2.34k forks source link

Fix Autotools-generated `libzmq.pc` file #4667

Closed hebasto closed 3 months ago

hebasto commented 3 months ago

On the master branch @ 481cc3fa2c4414e407d863b4428f1efd5441e97d, cross-compiling for Windows with static linking fails when relying on the libzmq.pc file.

Consider the minimum reproducible zmq_win_demo.cpp source file:

$ cat zmq_win_demo.cpp 
#include <zmq.h>

int main()
{
    auto ctx = zmq_ctx_new();
    zmq_ctx_term(ctx);
}

and steps to reproduce the bug as follows:

$ ZMQ_INSTALL_PATH=<set_any_path_at_your_choice>
$ ./autogen.sh
$ ./configure --host=x86_64-w64-mingw32 --prefix="$ZMQ_INSTALL_PATH" --disable-shared --disable-drafts --disable-libbsd --disable-perf --disable-Werror
$ make install
$ x86_64-w64-mingw32-g++-posix -static zmq_win_demo.cpp -DZMQ_STATIC $(env PKG_CONFIG_PATH="${ZMQ_INSTALL_PATH}/lib/pkgconfig pkg-config --static --cflags --libs libzmq) -o zmq_win_demo.exe
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/TEST_INSTALL_ZMQ/lib/libzmq.a(libzmq_la-zmq.o):/home/hebasto/git/libzmq/src/zmq.cpp:1033: undefined reference to `__imp_select'
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/TEST_INSTALL_ZMQ/lib/libzmq.a(libzmq_la-zmq.o): in function `zmq_poll':
/home/hebasto/git/libzmq/src/zmq.cpp:1073: undefined reference to `__WSAFDIsSet'
...

This PR fixes this bug.


Please note that CMake-generated libzmq.pc file is also broken as its "Libs.private" section contains only -lstdc++ when cross-compiling for Windows. I leave this problem out of this PR scope.