受欢迎的博客标签

How to find *.so

Published

How to Fix “cannot open shared object file” Error in Ubuntu

How to find *.so

 

linux 缺少动态连接库.so(cannot open shared object file: No such file or directory)解决办法

https://blog.csdn.net/Kena_M/article/details/108349698

 

Describle

An unhandled exception occurred while processing the request.
DllNotFoundException: Unable to load shared library 'ClearScriptV8.linux-x64.so' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.0/ClearScriptV8.linux-x64.so: cannot open shared object file: No such file or directory

 

Linux 运行的时候,是如何管理共享库(*.so)的?

在 Linux 下面,共享库的寻找和加载是由 /lib/ld.so 实现的。 ld.so 在标准路经(/lib, /usr/lib) 中寻找应用程序用到的共享库。

但是,如果需要用到的共享库在非标准路经,ld.so 怎么找到它呢?

way 1:将非标准路经加入 /etc/ld.so.conf

目前,Linux 通用的做法是将非标准路经加入 /etc/ld.so.conf,然后运行 ldconfig 生成 /etc/ld.so.cache。 ld.so 加载共享库的时候,会从 ld.so.cache 查找。

way 2:LD_LIBRARY_PATH 来处理非标准路经的共享库

传统上,Linux 的先辈 Unix 还有一个环境变量:LD_LIBRARY_PATH 来处理非标准路经的共享库。ld.so 加载共享库的时候,也会查找这个变量所设置的路经。

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib

export LD_LIBRARY_PATH

但是,有不少声音主张要避免使用 LD_LIBRARY_PATH 变量,尤其是作为全局变量。这些声音是:

* LD_LIBRARY_PATH is not the answer - http://prefetch.net/articles/linkers.badldlibrary.html

* Why LD_LIBRARY_PATH is bad - http://xahlee.org/UnixResource_dir/_/ldpath.html 

* LD_LIBRARY_PATH - just say no - http://blogs.sun.com/rie/date/20040710

way 3:在编译的时候通过 -R<path> 选项指定 run-time path

解决这一问题的另一方法是在编译的时候通过 -R<path> 选项指定 run-time path。

1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个library会找不到

2. 想往上面两个目录以外加东西的时候,一定要修改/etc/ld.so.conf,然后再调用ldconfig,不然也会找不到。

比如安装了一个mysql到/usr/local/mysql,mysql有一大堆library在/usr/local/mysql/lib下面,这时就需要在/etc/ld.so.conf下面加一行/usr/local/mysql/lib,保存过后ldconfig一下,新的library才能在程序运行时被找到。

3. 如果想在这两个目录以外放lib,但是又不想在/etc/ld.so.conf中加东西(或者是没有权限加东西)。那也可以,就是export一个全局变量LD_LIBRARY_PATH,然后运行程序的时候就会去这个目录中找library。一般来讲这只是一种临时的解决方案,在没有权限或临时需要的时候使用。

4. ldconfig做的这些东西都与运行程序时有关,跟编译时一点关系都没有。编译的时候还是该加-L就得加,不要混淆了。

5. 总之,就是不管做了什么关于library的变动后,最好都ldconfig一下,不然会出现一些意想不到的结果。不会花太多的时间,但是会省很多的事。

LD_LIBRARY_PATH 这个环境变量是大家最为熟悉的,它告诉loader:在哪些目录中可以找到共享库。可以设置多个搜索目录,这些目录之间用冒号分隔开。在linux下,还提供了另外一种方式来完成同样的功能,你可以把这些目录加到/etc/ld.so.conf中,然后调用ldconfig。当然,这是系统范围内全局有效的,而环境变量只对当前shell有效。按照惯例,除非你用上述方式指明,loader是不会在当前目录下去找共享库的,正如shell不会在当前目前找可执行文件一样。

 

 

root@vultr:~# find / -name "*.so"

 

/usr/lib/python3.8/lib-dynload/_hashlib.cpython-38-x86_64-linux-gnu.so
/usr/lib/python3.8/lib-dynload/nis.cpython-38-x86_64-linux-gnu.so
/usr/lib/gcc/x86_64-linux-gnu/9/liblsan.so
/usr/lib/gcc/x86_64-linux-gnu/9/libitm.so

 

apt search ClearScriptV8.linux-x64.so