ldconfig命令的作用是:
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.
ldconfig幾個需要注意的地方!
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一下,不然會出現一些意想不到的結果。不會花太多的時間,但是會省很多的事