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

时间:2012-09-18 03:47:36

标签: c linker osx-mountain-lion zeromq dylib

尝试从zeromq教程编译示例hello_world.c: http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive 很确定我已经在OSX Mountain Lion中安装了所有东西。

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/

1 个答案:

答案 0 :(得分:27)

您在问题中列出了ZeroMQ库,但实际上并没有链接。将命令行更改为:

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

额外参数的解释:

  • -L/usr/local/lib告诉链接器将路径(/usr/local/lib)添加到库搜索路径。
  • -lzmq告诉图书馆链接zmq库。

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