14

尝试从 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

并回显 $PATH:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/:/usr/local/include/
4

1 回答 1

30

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

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

额外参数的解释:

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

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

于 2012-09-18T05:16:38.730 回答