0
  • I have build zeroMQ solution i.e libzmq and czmq, I have used cmake-3.13 to configure and generate while vs 2015 to build solution for my Windows 10 system.
  • I was able to run czmq_selftest.exe successfully but when I try to run the example code I get the following error-

Here is my directory structure-

C:\Program Files\czmq\examples\security\hello.c C:\Program Files\czmq\include

hello.c

#include <czmq.h>

int main (void) {
    zsock_t *publisher = zsock_new (ZMQ_PUB);
    zsock_set_curve_server (publisher, true);
    puts ("Hello, Curve!");
    zsock_destroy(&publisher);
    return 0;
}

I am using "MinGW64" for compiling the above code-

Initially the above code gives me

$ gcc hello.c -o hello hello.c:5:10: fatal error: czmq.h: No such file or directory

While I tried manually giving the header file path I get-

gcc hello.c -o hello -I "C:\Program Files\czmq\include"

C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x22): undefined reference to `__imp_zsock_new_checked'
C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x3b): undefined reference to `__imp_zsock_set_curve_server'
C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x64): undefined reference to `__imp_zsock_destroy_checked'
collect2.exe: error: ld returned 1 exit status

I can't find any information which can help me solve this error.

gadhvi
  • 97
  • 2
  • 11
  • It's not clear to me where `cmake` comes in here. Are you saying that you used it to build and install zeroMQ? It does not appear that you're using it with the test program you're trying to build, but I'm uncertain. – John Bollinger Jan 15 '19 at 14:05
  • 1
    The errors reported at the end are *link* errors, which you will only get if the C compilation was successful. IOW, your `-I` option did what you wanted it to do. But you also need to tell the linker where to look for the corresponding library files. In `gcc` and many other systems, that role is filled by the `-L` option. – John Bollinger Jan 15 '19 at 14:09
  • @JohnBollinger I have downloaded binaries of ZeroMQ and have configured, generated using CMake and then i have build the .sln using Visual Studio 2015 SDK 8.1 x64. I tried the above command `$ gcc hello.c -o hello -I "C:\ZeroMQ\czmq\include" -L "C:\ZeroMQ\czmq\builds\cmake\Debug\libczmq.lib"` I am still getting same error- `C:\Ruby25-x64\msys64\tmp\ccjNjDFn.o:hello.c:(.text+0x22): undefined reference to __imp_zsock_new_checked' ` – gadhvi Jan 16 '19 at 04:51
  • The `-L directory` option tells the linker to search `directory` for libraries that you tell it to link. It does not tell it link any libraries. The `-l name` option does that. Tell it where to search *and* what library to link: `-L C:\ZeroMQ\czmq\builds\cmake\Debug -lczmq` – Mike Kinghan Jan 25 '19 at 12:15
  • @MikeKinghan Yes later I used msi installer and fixed missing library issue just by adding there reference in PATH variable and copying some dlls to system32. I didn't get the link issue using installer so maybe there was some issue with binaries .. – gadhvi Jan 29 '19 at 09:22

1 Answers1

0

You should change first line like this:

#include "path/czmq.h"

This is the way to tell C include file is in different directory

If include file is in to the same directory the line become

#include "czmq.h"

The second error IMHO mean you do not have proper definitions in include file

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • 1
    I don't disagree enough to downvote, but no, not really. Specifying (relative) paths in the `#include` directive makes sense only where the path is a well-known characteristic of the header being included. It is *not* appropriate for adapting to different header installation locations. For the latter, one wants to use a compiler option to specify additional directories to check, exactly as the OP already describes. – John Bollinger Jan 15 '19 at 14:01