今天配置之前項目的時候,發現有些動態鏈接庫變了,想看看現在應用在使用哪些動態鏈接庫的時候,進一步查了點資料; 下麵針對linux動態鏈接庫查找方法和動態鏈接庫位置配置的過程進行記錄: LIBRARY_PATH 和 LD_LIBRARY_PATH 的區別: (參考鏈接) LIBRARY_PATH is ...
今天配置之前項目的時候,發現有些動態鏈接庫變了,想看看現在應用在使用哪些動態鏈接庫的時候,進一步查了點資料;
下麵針對linux動態鏈接庫查找方法和動態鏈接庫位置配置的過程進行記錄:
LIBRARY_PATH 和 LD_LIBRARY_PATH 的區別: (參考鏈接)
LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program. LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked.
As pointed below, your libraries can be static or shared. If it is static then the code is copied over into your program and you don't need to search for the library after your program is compiled and linked. If your library is shared then it needs to be dynamically linked to your program and that's when LD_LIBRARY_PATH
comes into play.
LD_LIBRARY_PATH and LD_RUN_PATH 的區別: (參考鏈接)
LD_RUN_PATH is used for the link time resolution of libraries whilst LD_LIBRARY_PATH is used for run time resolution of libraries. LD_RUN_PATH Specifies the directories that are to be searched for libraries at both link and run time. LD_LIBRARY_PATH indicates to the dynamic loader to search the colon delimited paths for libraries required to execute the binary. LD_RUN_PATH is used by the linker to specify where to look for libraries only at run time. This differs ever so slightly from LD_LIBRARY_PATH in that this set of paths are not searched during link time.
動態鏈接庫查找路徑配置:
1. 可以使用上面 LD_LIBRARY_PATH 等環境變數進行配置;
2. 可以使用 /etc/ld.so.conf 全局配置文件,配置動態鏈接庫運行時的搜索路徑; 然後使用ldconfig命令,進行將/etc/ld.so.conf載入到ld.so.cache之中(需要root許可權);
3. 然後使用:ldconfig -p | grep "your lib" 進行查找所需要動態鏈接庫的位置;
4. 針對已有程式,可以使用 ldd "your bin" 進行直接看當前執行程式所需要的鏈接庫的情況;
保持更新,轉載請註明出處;更多內容,請關註 cnblogs.com/xuyaowen;
/etc/ld.so.conf.d/x86_64-linux-gnu.conf,多體繫結構支持配置,以x86_64為例:
# Multiarch support /usr/local/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
保持更新;