本文介绍了编译简单的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-ReceivePretty 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库,但实际上并没有与其进行 link 链接.将命令行更改为此:

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示例,编译标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:14