首页 > 其他分享> > ZeroMQ(一)——error while loading shared libraries: libzmq.so.5: cannot open shared object解决方案
ZeroMQ(一)——error while loading shared libraries: libzmq.so.5: cannot open shared object解决方案
作者:互联网
问题
下面是一段调用ZeroMQ接口的程序:
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REP);
socket.bind ("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv (&request);
std::cout << "Received Hello" << std::endl;
// Do some 'work'
sleep (1);
// Send reply back to client
zmq::message_t reply (5);
memcpy ((void *) reply.data (), "World", 5);
socket.send (reply);
}
return 0;
}
编译运行时报错
[root@192 day20211007]# g++ server.cpp -o server -lzmq
[root@192 day20211007]# ls
server server.cpp
[root@192 day20211007]# ./server
./server: error while loading shared libraries: libzmq.so.5: cannot open shared object file: No such file or directory
解决方案
(1)打开/etc/ld.so.conf文件
[root@192 day20211007]# vim /etc/ld.so.conf
(2) 在文件中添加libzmq.so.5所在的路径,我的路径为/usr/local/lib
include ld.so.conf.d/*.conf
/usr/local/lib/
(3)修改完成保存,执行ldconfig命令刷新动态库
root@192 day20211007]# ldconfig
标签:libzmq,loading,socket,day20211007,192,include,shared,server,root 来源: https://blog.csdn.net/www_dong/article/details/120642852