wizir
wizir

Reputation: 71

ZeroMQ compilation fails with gcc/g++ on windows

I have 2 programs communicationg with each other: "server" written in GO running on Linux and "client" in c++ on Windows.

I have 3 files:
zmq.h
libzmq-v120-mt-4_0_4.lib
libzmq-v120-mt-4_0_4.dll

The client is an example from http://zguide.zeromq.org/c:hwclient and it compiles fine on linux with command line:

g++ zmq.h client.cpp -lzmq

I can compile the program on Windows with architecture x64 using Visual Studio and linking the *.lib file. Still, to run the program I need the *.dll file to be in the output directory, but that's ok.

The problem is that I don't want to use Visual Studio IDE and use gcc or g++ instead. No matter what I try I always get these errors

C:\..\client>g++ zmq.h main.cpp -L libzmq-v120-mt-4_0_4.lib
..\ccQafArl.o:main.cpp:(.text+0x1c): undefined reference to `__imp_zmq_ctx_new'
..\ccQafArl.o:main.cpp:(.text+0x35): undefined reference to `__imp_zmq_socket'
..\ccQafArl.o:main.cpp:(.text+0x50): undefined reference to `__imp_zmq_connect'
..\ccQafArl.o:main.cpp:(.text+0x91): undefined reference to `__imp_zmq_send'
..\ccQafArl.o:main.cpp:(.text+0xb1): undefined reference to `__imp_zmq_recv'
..\ccQafArl.o:main.cpp:(.text+0xd8): undefined reference to `__imp_zmq_close'
..\ccQafArl.o:main.cpp:(.text+0xe8): undefined reference to `__imp_zmq_ctx_destroy'
collect2.exe: error: ld returned 1 exit status

It looks like g++ can't find the *.lib file but then how does VS compile with no errors? I have tried TDM-GCC-32, TDM-GCC-64 and and mingw64 g++ every time with the same result. ZeroMQ is installed with windows installer, not from source.

How can I make it to compile on Windows without using Visual Studio?

Upvotes: 3

Views: 1371

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385174

That's not how you link libraries.

Firstly, you're using -L, which specifies a library search path, not a library.

You're looking for -l, and this takes a name, not a filename.

So:

-l lzmq-v120-mt-4_0_4

The linker should automatically search for matching files with the proper prefix and the proper extension for that platform (.so, .a, .lib, whatever).

(You got this right in the previous example.)

Have a little read of the documentation.

Upvotes: 1

Related Questions