error while loading shared libraries: xxx.so.x" 报错与解决

13 篇文章 0 订阅

error while loading shared libraries: libevent_pthreads-2.0.so.5: cannot open 

shared object file: No such file or directory

今天在执行一代码时,出现了该错误代码如下
#include<event.h>
#include<stdio.h>
#include<unistd.h>
#include<event2/thread.h>

#include<pthread.h> //Linux thread

struct event_base *base = NULL;


void pipe_cb(int fd, short events, void *arg)
{
printf("in the cmd_cb\n");
}

void timeout_cb(int fd, short events, void *arg)
{
printf("in the timeout_cb\n");
}

void* thread_fn(void *arg)
{
char ch;
scanf("%c", &ch); //just for wait

struct event *ev = event_new(base, -1, EV_TIMEOUT | EV_PERSIST,
timeout_cb, NULL);

struct timeval tv = {2, 0};
event_add(ev, &tv);
}

int main(int argc, char ** argv)
{
if( argc >= 2 && argv[1][0] == 'y')
evthread_use_pthreads();

base = event_base_new();
evthread_make_base_notifiable(base);

int pipe_fd[2];
pipe(pipe_fd);
printf("%d %d\n",pipe_fd[0],pipe_fd[1]);
struct event *ev = event_new(base, pipe_fd[0],
EV_READ | EV_PERSIST, pipe_cb, NULL);

event_add(ev, NULL);

pthread_t thread;
pthread_create(&thread, NULL, thread_fn, NULL);


event_base_dispatch(base);

return 0;
}
编译的时候需要链接 -lpthread、-levent和-levent_pthreads,执行之后发现报错

解决方法为:共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
重启之后便能够解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值