Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile simple hello world ZeroMQ C example, compile flags?

Trying to compile the example hello_world.c from the zeromq tutorial: http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive Pretty sure I have everything installed in OSX Mountain Lion.

clang -Wall hwserver.c -o hwserver

gives me an error:

Undefined symbols for architecture x86_64:  
"_zmq_bind", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_ctx_new", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_close", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_data", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_init", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_init_size", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_recv", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_msg_send", referenced from:  
  _main in hwserver-OgrEe6.o  
"_zmq_socket", referenced from:  
  _main in hwserver-OgrEe6.o  
ld: symbol(s) not found for architecture x86_64  
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not the most experienced in C. Not sure if I sure be adding a compiler flag for the zmq dylib or headers or my $PATH being off.

in /usr/local/lib:

libzmq.3.dylib
libzmq.a
libzmq.dylib
libzmq.la

and in /usr/local/include:

zmq.h
zmq_utils.h

and echo $PATH:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/:/usr/local/include/
like image 663
Nick Desaulniers Avatar asked Sep 18 '12 03:09

Nick Desaulniers


1 Answers

You list the ZeroMQ libraries in your question, but you do not actually link with them. Change the command line to this:

clang -Wall hwserver.c -o hwserver -L/usr/local/lib -lzmq

Explanation of the extra arguments:

  • -L/usr/local/lib tells the linker to add a path (/usr/local/lib) to the library search path.
  • -lzmq tells the library to link with the zmq library.

The $PATH environment variable have nothing to do with this, it just tells the shell where to look for commands.

like image 138
Some programmer dude Avatar answered Oct 04 '22 21:10

Some programmer dude