更新时间:2022-05-18 22:56:33
如果要dlopen的库不在标准搜索路径中,则有很多选择:
If the library you want to dlopen is not in the standard search path you have a number of options:
在dlopen中指定文件的完整路径
Specify the full path to the file in dlopen
dlopen("/full/path/to/libfile.so");
通过LD_LIBRARY_PATH将路径添加到库
Add the path to the library via LD_LIBRARY_PATH
LD_LIBRARY_PATH=/path/to/library/ ./executable
使用ld -rpath选项向应用程序添加库路径.
use the ld -rpath option to add a library path to the application.
g++ -link stuff- -Wl,-rpath=/path/to/library/
请注意,选项1& 3将库路径硬编码到您的应用程序中. -rpath确实具有指定相对路径的选项,即
Note that options 1 & 3 hardcode the library path into your application. -rpath does have an option to specify a relative path, i.e.
-Wl,-rpath=$ORIGIN/../lib/
将相对路径嵌入到应用程序中.
Will embed a relative path into the application.