Error While Loading Shared Libraries, Cannot Open Shared Object File
In the “I wish the Internet had an actual correct answer” category comes a question from a Windows colleague trying to build software on Linux. He asks “I’m trying to do some web performance testing and I compiled weighttp
and the libev libraries, which worked fine, but when I try to run the program it gives me the following error.”
weighttp: error while loading shared libraries: libev.so.4: cannot open shared object file: No such file or directory
“I checked /usr/local/lib and the files are there. Do you have a suggestion?”
Ah yes, a classic problem when building software. The problem here is that libev installed itself into /usr/local/lib:
$ ls-l /usr/local/lib/libev*
-rw-r--r--.1 root root 435770 Feb2215:20/usr/local/lib/libev.a
-rwxr-xr-x.1 root root 926 Feb2215:20/usr/local/lib/libev.la
lrwxrwxrwx.1 root root14 Feb 2215:20/usr/local/lib/libev.so-> libev.so.4.0.0
lrwxrwxrwx.1 root root14 Feb 2215:20/usr/local/lib/libev.so.4-> libev.so.4.0.0
-rwxr-xr-x.1 root root 174059 Feb2215:20/usr/local/lib/libev.so.4.0.0
…but the dynamic linker doesn’t know where they are, because it’s never heard of /usr/local/lib. /usr/local is a traditional place for add-on software to install itself, so it doesn’t interfere with the system libraries.
If you’re coming from a Windows background the .so files are essentially equal to DLLs, and load when you execute a program that depends on them. Programs that use dynamic libraries have several advantages, in that they’re smaller, and the libraries can be
updated without having to recompile all the programs that depend on them. So if there’s a security problem with libev you can just patch libev, and not have to rebuild everything that uses that library.
You can see what libraries a program is dynamically linked to with the ‘ldd’ command:
$ ldd /usr/local/bin/weighttp
linux-vdso.so.1 => (0x00007fff251ff000)
libev.so.4 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f8f1cc1e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8f1c88b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8f1ce49000)
That confirms we’re just dealing with the new library, and not some other problem. Cool.
Anyhow, there are five fixes that come to mind, and I’ll group them into “terrible ideas” and “decent ideas.” Of course, terrible and decent are my opinion, and your situation may dictate a different conclusion, so I’ll
add some commentary. If you’re looking for the quickest way out skip to #5.
Suboptimal Fixes/Terrible Ideas[0]
1.Install the libraries to /usr/lib instead of /usr/local/lib. I really don’t like this because you’re installing add-on software into a system directory,and you might introduce a conflict, overwrite a pre-existing library,
and/or destabilize other parts of the system. People complain about Windows being unstable, and this sort of thing is exactly why it gets unstable – installers overwrite system DLLs with their own all the time. Recent versions of Windows go to a lot of trouble
to keep installers from doing this. If you’re bored lookup the WinSxS subsystem, which is what Microsoft built to deal with the problem. Linux doesn’t have something that deals with the problem, it just assumes that you know what you’re doing. Such is the
power of UNIX. Here’s a rope, try not to hang yourself.
When you’re building open-source software under a UNIX OS you often use the “configure” command. You can change where the software installs by using the “prefix” flag:
$ ./configure –prefix=/usr
This will also install all the binaries, header files, etc. into the system directories. If you were one of my system administrators I’d get on your case for doing this and make you go back and do it right. This isn’t
the right way. Don’t do it this way. The right ways are simple, do those instead.
2. Make a symbolic link from /lib to the files in /usr/local/lib. This is less intrusive than installing everything to /usr, but still a bad idea, for most of the same reasons as #1.If you’re the kind of person that likes
to smoke while refueling vehicles go ahead and try:
$ sudo ln -s /usr/local/lib/libev.so.4 /usr/lib/libev.so.4
$ sudo ldconfig
Obviously substitute the correct file name for libev.so.4. The ‘ldconfig’ command updates the system’s dynamic library cache so it sees the changed libraries.
Still, don’t do this. Bad sysadmin.
3. Copy the files from/usr/local/lib into /usr/lib. This is even more of a bad idea than #2 because now you’ve got two sets of libraries, and if you ever have to patch or upgrade it you’ll probably forget about one set.
Oops. I hope you weren’t patching because of a security problem!
$ sudo cp /usr/local/lib/libev.* /usr/lib
$ sudo ldconfig
With all these ideas you’re also very likely to run afoul of the 32-bit vs. 64-bit thing with newer OSes, where 32-bit libraries go in /usr/lib and 64-bit libraries go in /usr/lib64. It might work, it might not work,
but the better ways are a heck of a lot simpler.
Better Idea
4. Set the environment variable LD_LIBRARY_PATH to point to /usr/local/lib. If you are new to UNIX/Linux and don’t know what shell you’re running, use the ‘ps’ command to see the processes you’re running:
$ ps
PID TTY TIME CMD
7796 pts/4 00:00:00 tcsh
10048 pts/4 00:00:00 ps
Hey look, I’m running tcsh, so my fix would be:
setenv LD_LIBRARY_PATH /usr/local/lib
and I can put that command into ~/.cshrc so it executes when I log in.
If ps tells you you’re running bash:
$ ps
PID TTY TIME CMD
7796 pts/4 00:00:00 bash
10048 pts/4 00:00:00 ps
the command is:
export LD_LIBRARY_PATH="/usr/local/lib"
and you can put that into your ~/.bashrc so it’s always there.
Changing the environment is a per-user thing, so other users on the system will need to do this, or you’d need to put the fixes in /etc/bashrc or /etc/csh.cshrc, the system-wide login scripts. This fix is nice, though,
if you don’t have root-level privileges on a system, and/or want to install things into your own home directory.
Absolutely Simple, Best FixEver[2]
5. If you have root privileges on this Linux box, why not just ask the dynamic linker to check /usr/local/lib, too? Edit the file /etc/ld.so.conf and add “/usr/local/lib” on its own line at the bottom[3]. DO NOT REMOVE
THINGS FROM THIS FILE. When you’re done it might look something like:
$ cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
or it might look completely different, with the exception of the last line. Run ldconfig to tell it to update the cache:
$ sudo ldconfig
You can check your work with:
$ ldconfig -p | grep local
You should see the stuff in/usr/local/lib show up now, and your binary works. Boy, that was easy, and you didn’t make more work for yourself down the road, destabilize the system, overwrite system files, or leave security
vulnerabilities lying around. Cool.
Good luck. As always, if you see a problem here let me know in the comments. If you have other questions you’d like me to answer in a blog post you should email them or tweet them at me! Mycontact information is on the
top-right at lonesysadmin.net. While you’re there why don’t you subscribe to my feed, too?
———
[0] So why did I list the bad ideas? Because you’ll see every one suggested as a fix by people pretending tobe experts[1]. It is my hope that you’ll understand why these are bad ideas,why they might cause you more work
in the long run, and can make an informeddecision.
[1] I am not an expert, I’m a guy that’s done a lot of this stuff, and might be able to answer your question. If someone calls themselves an expert run away.
[2] Not guaranteed to be simple or best. I like it, though.
[3] If you’re stymied by editing on the command line try “nano.” It’s a simple editor and is often installed. Another option is ‘vi’ but it’s cryptic, and you can use Google to find a tutorial on it if you need one. The
nice thing about vi is that it’s always installed.
https://lonesysadmin.net/2013/02/22/error-while-loading-shared-libraries-cannot-open-shared-object-file/
Error While Loading Shared Libraries, Cannot Open Shared Object File的更多相关文章
- 解决 Linux error while loading shared libraries: cannot open shared object file: No such file or directory
安装最新版本Emqtt,参照官方文档安装后,执行报错: Linux error while loading shared libraries libsctp.so.1: cannot open sha ...
- [持续交付实践] pipeline使用:Shared Libraries
前言 随着pipeline交付流水线在团队中的推广,使用pipeline脚本的job也迅速增加.虽然我们已经基于公司的技术栈特点做了一个尽可能通用的pipeline脚本样例,让搭建者只需要修改几个赋值 ...
- linux使用wkhtmltopdf报错error while loading shared libraries:
官网提示 linux需要这些动态库.depends on: zlib, fontconfig, freetype, X11 libs (libX11, libXext, libXrender) 在li ...
- python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory
安装python3遇到报错: wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz ./configure --prefix=/u ...
- error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
zabbix3.2启动有如下报错: # service zabbix_server startStarting zabbix_server: /home/zabbix-server/sbin/zab ...
- 错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
执行以下代码,生成唯一的UID $fp = popen("/xxx/bin/tools/uuidgen system", "r");// $uid = frea ...
- ebs r12 -- adadmin: error while loading shared libraries: libclntsh.so.10.1
安装EBS R12.2增加中文字符集时,运行$AU_TOP/bin/adadmin出错: $ adadmin adadmin: error while loading shared libraries ...
- 【转】error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
错误信息: /usr/local/memcacheq/bin/memcacheq: error while loading shared libraries: libevent-2.0.so.5: c ...
- ssh 发现了error while loading shared libraries这种错
在Linux下运行程序时,发现了error while loading shared libraries这种错误,一时间不知道解决办法,在网上搜索,终于解决了: ./tests: error whil ...
随机推荐
- NYOJ1367 物流配送
题目描述: 物流配送是物流活动中一种非单一的业务形式,它与物品流动.资金流动紧密结合.备货是配送的准备工作或基础工作,备货工作包括筹集货源.订货或购货.集货.进货及有关的质量检查.结算.交接等.配送的 ...
- jodatime 计算时间差_统计程序运行耗时
https://blog.csdn.net/De_Moivre/article/details/79775661 记录开始执行的时间 DateTime startDateTime=new DateTi ...
- 独立版的 Asio安装与使用
Asio分为独立版和Boost版.两者使用方法基本一致,只是头文件不同.Boost版是作为Boost的子库提供的. 因为Asio的组织形式为hpp文件(不同一般的C++项目区分头文件.h和源文件.cp ...
- uva 11300 分金币(利用绝对值加和进行求出最小值)
//qq 767039957 welcome #include<cstdio> #include<algorithm> #include<vector> #incl ...
- Leetcode54. Spiral Matrix螺旋矩阵
给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素. 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ...
- 如何用git将项目代码上传到github - CSDN博客
配置Git 我们先在电脑硬盘里找一块地方存放本地仓库,比如我们把本地仓库建立在C:\MyRepository\1ke_test文件夹下 进入1ke_test文件夹 鼠标右键操作如下步骤: 1)在本地仓 ...
- 2018.8.6 模拟赛 提高组B
T1 Description 给定一个n个点m条边的有向图,有k个标记点,要求从规定的起点按任意顺序经过所有标记点到达规定的终点,问最短的距离是多少. Input 第一行5个整数n.m.k.s.t,表 ...
- Linux常用命令操作详解
https://mp.weixin.qq.com/s/IR4yy7Q0mOA_XV16R21CdQ 一:Linux下tomcat服务的启动.关闭与错误跟踪 使用PuTTy远程连接到服务器以后,通常通过 ...
- 【Mobius绮丽的辗转】莫比乌斯反演
Problem 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 1≤n≤50000,1≤a≤b≤5 ...
- 为什么不用原生的Spring Cloud Config
引言 近几年传统应用架构已经逐渐朝着微服务架构演进.那么随着业务的发展,微服务越来越庞大,此时服务配置的管理变得会复杂起来.为了方便服务配置文件统一管理,实时更新,配置中心应运而生.其实,所谓配置中心 ...