编译简单的 hello world ZeroMQ C 示例,编译标志? [英] Compile simple hello world ZeroMQ C example, compile flags?

查看:33
本文介绍了编译简单的 hello world ZeroMQ C 示例,编译标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

给我一​​个错误:

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 已关闭.

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.

在/usr/local/lib 中:

in /usr/local/lib:

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

并在/usr/local/include 中:

and in /usr/local/include:

zmq.h
zmq_utils.h

并回显 $PATH:

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

推荐答案

您在问题中列出了 ZeroMQ 库,但实际上并没有与它们链接.把命令行改成这样:

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

额外参数的解释:

  • -L/usr/local/lib 告诉链接器将路径(/usr/local/lib)添加到库搜索路径.
  • -lzmq 告诉库与 zmq 库链接.
  • -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.

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

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

这篇关于编译简单的 hello world ZeroMQ C 示例,编译标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆