Linux dlopen() 搜索路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8193640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:22:53  来源:igfitidea点击:

dlopen() search path

clinuxdlopen

提问by user1055225

is there a way to find out programmatically which paths are searched by dlopen() for shared objects? I always thought dlopen() would only look in /lib and /usr/lib but now I've seen that on Linux Mint several core components like libglib-2.0.so are in a wholly different folders, namely in /rofs/lib/i386-gnu-linux and some others. Is there a way to get to know all these paths that dlopen() will search through for a shared object? I already checked the environment variable LD_LIBRARY_PATH but it's not defined at all.

有没有办法以编程方式找出 dlopen() 为共享对象搜索哪些路径?我一直认为 dlopen() 只会在 /lib 和 /usr/lib 中查找,但现在我看到在 Linux Mint 上,libglib-2.0.so 等几个核心组件位于完全不同的文件夹中,即 /rofs/lib/ i386-gnu-linux 和其他一些。有没有办法了解 dlopen() 将搜索共享对象的所有这些路径?我已经检查了环境变量 LD_LIBRARY_PATH 但它根本没有定义。

采纳答案by Brett Hale

look at the ldconfigman page, and the file: /etc/ld.so.conf

查看ldconfig手册页和文件:/etc/ld.so.conf

回答by Basile Starynkevitch

In addition of the ld.so.confhint:

另外ld.so.conf提示:

If you want to ensure that a specific library is dlopen-ed, pass a path to dlopen, e.g. dlopen("/some/path/to/lib.so", RTLD_LOCAL)or maybe dlopen("./lib.so", RTLD_LOCAL)but not dlopen("lib.so", RTLD_LOCAL)

如果你想确保一个特定的库被dlopen-ed,传递一个路径到dlopen,例如dlopen("/some/path/to/lib.so", RTLD_LOCAL)或者可能dlopen("./lib.so", RTLD_LOCAL)但不是 dlopen("lib.so", RTLD_LOCAL)