2、ldd 顯示依賴庫,ldd能夠顯示可執行模塊的dependency,其原理是通過設置一系列的環境變量,如下: LD_TRACE_LOADED_OBJECTS、LD_WARN、LD_BIND_NOW、LD_LIBRARY_VERSION、 LD_VERBOSE等。當LD_TRACE_LOADED_OBJECTS環境變量不爲空時,任何可執行程序在運行時,它都會只顯示模塊的 dependency,而程序並不真正執行。要不你可以在shell終端測試一下,如下:
(1) export LD_TRACE_LOADED_OBJECTS=1
(2) 再執行任何的程序,如ls等,看看程序的運行結果
3、 ldd顯示可執行模塊的dependency的工作原理,其實質是通過ld-linux.so(elf動態庫的裝載器)來實現的。我們知道,ld- linux.so模塊會先於executable模塊程序工作,並獲得控制權,因此當上述的那些環境變量被設置時,ld-linux.so選擇了顯示可執 行模塊的dependency。
4、實際上可以直接執行ld-linux.so模塊,如:/lib/ld-linux.so.2 --list program(這相當於ldd program)
onebyte:
ldd的作用:最近我的程序一直運行不起來,也很想用ldd看一下其到底加載了哪些運行庫,但由於在HOST上已交叉編譯過,所以在HOST上用 ldd無果。後來一直沒有什麼好的辦法。今天看了這篇文章才恍然大悟,原來ldd只是個腳本文件,那不是直接將其拷貝到TARGET就可以了嗎?
俺立刻動手,果然好使!發現我的程序原來少了libqte.so.3的庫,太好了!從HOST上拷一個過來就OK:)
現在我的程序加載是沒有問題了(當你拷貝新的動態鏈接庫到TARGET上後,建議重啓一下機子),雖然出現一些其它錯誤,但總算又前進一步:)
--------------------------------
ldd - print shared library dependencies
SYNOPSIS
ldd [OPTION]... FILE...DESCRIPTION
ldd prints the shared libraries required by each program or shared library specified on the command line.OPTIONS
- --version
- Print the version number of ldd.
- -v --verbose
- Print all information, including e.g. symbol versioning information.
- -d --data-relocs
- Perform relocations and report any missing objects (ELF only).
- -r --function-relocs
- Perform relocations for both data objects and functions, and report any missing objects or functions (ELF only).
- --help
- Usage information.