首先运行编译 sample 中的 hello.c,命令如下: -levent 表示 动态链接库
生成 hello 可执行文件,运行 ./hello ,出现如下错误:
./hello: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
原因是:系统不知道 libevent-2.0.so. 放在哪个目录下,这个时候就要在 /etc/ld.so.conf 中加入 libevent-2.0.so 所在的目录。
首先,先找到 /etc/ld.so.conf
![]()
然后 将路径添加进去:
![]()
最后,更新配置,输入 ldconfig。
此时会出现 “/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied” 权限受限,
改成 sudo ldconfig 即可。
![]()

本文介绍了解决在编译和运行C程序时遇到的libevent动态链接错误的方法。通过在/etc/ld.so.conf中添加libevent库的路径,并使用sudo权限执行ldconfig命令来更新链接器缓存,最终解决了找不到libevent-2.0.so.5的问题。
2178

被折叠的 条评论
为什么被折叠?



