当先锋百科网

首页 1 2 3 4 5 6 7
一、运行个别工具时报错及原因分析

  笔者在 Linux 环境运行一个工具时,报如下错误。

error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

  报错提示:加载共享库时出错:libevent-1.4.so.2:无法打开共享对象文件:本机没有安装 libevent-1.4.so.2 或在库文件路径下不存在。

  可以通过如下命令检查本机是否安装了 libevent-1.4.so.2。

[root@vm]# ls -al /usr/lib | grep libevent
[root@vm]# ls -al /usr/lib64 | grep libevent

  上述命令未查找到对应的库文件,所以在运行依赖于该类库的工具时,报如上错误。解决方法是安装 libevent 即可。

二、libevent 安装步骤
2.1 下载安装包

  下载 libevent 安装包,官网地址:https://libevent.org/

  本文下载的是 libevent-1.4.14b-stable.tar.gz 版本,可以直接在浏览器打开 https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz 链接下载,或在 Linux 环境 wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz

2.2 解压

  将安装包上传到 Linux 服务器并解压。

2.3 配置、编译、安装

  切换到解压后的 libevent 主目录,配置安装路径,再编译及安装,步骤如下所示。

[root@vm]# cd libevent-1.4.14b-stable/

[root@vm]# ./configure --prefix=/usr

[root@vm]# make

[root@vm]# make install
2.4 创建软链接

  libevent 会安装到 /usr/lib 或 /usr/local/lib 下,本次安装在了 /usr/lib 路径下。可以创建一些软链接,使得其他程序运行时能找到 libevent 库,如在 /usr/lib64 下创建软链接。

2.5 查看是否安装成功

  可以分别查看不同类库路径下是否已有 libevent 库,来初步检查是否安装成功,如下所示。

[root@vm]# ls -al /usr/lib |grep libevent
lrwxrwxrwx   1 root root     21 May 10 15:46 libevent-1.4.so.2 -> libevent-1.4.so.2.2.0
-rwxr-xr-x   1 root root 442592 May 10 15:46 libevent-1.4.so.2.2.0
lrwxrwxrwx   1 root root     21 May 10 15:46 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9
lrwxrwxrwx   1 root root     32 May 10 10:53 libevent-2.0.so.5.1.9 -> /usr/lib64/libevent-2.0.so.5.1.9
-rw-r--r--   1 root root 806914 May 10 15:46 libevent.a
lrwxrwxrwx   1 root root     26 May 10 15:46 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.2.0
-rwxr-xr-x   1 root root 165584 May 10 15:46 libevent_core-1.4.so.2.2.0
-rw-r--r--   1 root root 270444 May 10 15:46 libevent_core.a
-rwxr-xr-x   1 root root    988 May 10 15:46 libevent_core.la
lrwxrwxrwx   1 root root     26 May 10 15:46 libevent_core.so -> libevent_core-1.4.so.2.2.0
lrwxrwxrwx   1 root root     27 May 10 15:46 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.2.0
-rwxr-xr-x   1 root root 345816 May 10 15:46 libevent_extra-1.4.so.2.2.0
-rw-r--r--   1 root root 644708 May 10 15:46 libevent_extra.a
-rwxr-xr-x   1 root root    995 May 10 15:46 libevent_extra.la
lrwxrwxrwx   1 root root     27 May 10 15:46 libevent_extra.so -> libevent_extra-1.4.so.2.2.0
-rwxr-xr-x   1 root root    953 May 10 15:46 libevent.la
lrwxrwxrwx   1 root root     21 May 10 15:46 libevent.so -> libevent-1.4.so.2.2.0
[root@vm]# 
[root@vm]# ls -al /usr/lib64 |grep libevent
lrwxrwxrwx   1 root root       30 May 10 16:03 libevent-1.4.so.2 -> /usr/lib/libevent-1.4.so.2.2.0
lrwxrwxrwx   1 root root       21 Jun 25  2019 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9
-rwxr-xr-x   1 root root   297792 Jun 14  2014 libevent-2.0.so.5.1.9
lrwxrwxrwx   1 root root       26 Jun 25  2019 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9
-rwxr-xr-x   1 root root   179800 Jun 14  2014 libevent_core-2.0.so.5.1.9
lrwxrwxrwx   1 root root       27 Jun 25  2019 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.9
-rwxr-xr-x   1 root root   133864 Jun 14  2014 libevent_extra-2.0.so.5.1.9
lrwxrwxrwx   1 root root       29 Jun 25  2019 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.9
-rwxr-xr-x   1 root root    24456 Jun 14  2014 libevent_openssl-2.0.so.5.1.9
lrwxrwxrwx   1 root root       30 Jun 25  2019 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.9
-rwxr-xr-x   1 root root    11200 Jun 14  2014 libevent_pthreads-2.0.so.5.1.9
[root@vm]# 

  可以看到两个路径下,均已存在 libevent-1.4.so.2。

  尝试再次运行开始报错的那个工具类,此时运行成功,不再报错。

文章参考: