我正在尝试安装 Zeromq,但遇到了一些问题: undefined reference 。我用过 this 在我的机器上安装 Zeromq 的教程,不同之处在于我下载的是 4.1.4 版本而不是 4.1.2。
然后我尝试在 C 中运行以下代码(来自 Zeromq 教程):
// Hello World server
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
int main (void)
{
// Socket to talk to clients
void *context = zmq_ctx_new ();
void *responder = zmq_socket (context, ZMQ_REP);
int rc = zmq_bind (responder, "tcp://*:5555");
assert (rc == 0);
while (1) {
char buffer [10];
zmq_recv (responder, buffer, 10, 0);
printf ("Received Hello\n");
sleep (1); // Do some 'work'
zmq_send (responder, "World", 5, 0);
}
return 0;
}
用这一行:
gcc program.c -lzmq
我得到了这个错误:
/tmp/cc3OkNsE.o: In function `main':
program.c:(.text+0x18): undefined reference to `zmq_ctx_new'
collect2: error: ld returned 1 exit status
我已经做了一些研究,但找不到任何明确的解决方案/说明。有人知道如何解决这个问题或者我做错了什么吗?
最佳答案
正如 Maarten Artis 在上面的评论中指出的那样,它实际上并没有链接该库。正确的命令行是:
gcc -Wall program.c -o prog -L/usr/local/lib -lzmq
关于c - 在 Ubuntu 16.04 64 位中安装 ZeroMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46131932/