编译简单的hello world ZeroMQ C的例子,编译标志?

尝试从zeromq教程编译示例hello_world.c:
http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive
相当肯定我有一切安装在OSX山狮.

clang -Wall hwserver.c -o hwserver

给我一个错误:

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)

我不是最有经验的C.不知道如果我确定添加一个编译器标志为zmq dylib或头或我的$PATH关闭.

在/usr/local / lib中:

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

并在/usr/local / include:

zmq.h
zmq_utils.h

和echo $PATH:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/:/usr/local/include/
最佳答案
您在问题中列出了ZeroMQ库,但实际上并没有链接到它们.将命令行更改为:

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

说明额外的论据:

> -L /usr/local / lib告诉链接器向库搜索路径添加路径(/usr/local / lib).
> -lzmq告诉库与zmq库链接.

$PATH环境变量与此无关,它只是告诉shell在哪里查找命令.

转载注明原文:编译简单的hello world ZeroMQ C的例子,编译标志? - 代码日志