大量warning:libb.so needed by liba.so not found.的問題解決方法

例如:warning:libb.so needed by liba.so not found.原因是:例如代碼引用了liba.so,但是liba.so又引用了libb.so,這種情況是由於makefile沒有顯示指定需要鏈接b.so,
解決這個問題目前有三種方法:1:在makefile裏面顯示鏈接-lb,2:可以增加rpath參數,指定libb.so的路徑3:可以將libb.so的路徑加入系統鏈接路徑/etc/ld.so.conf。

關於-Wl參數說明:
-Wl,option
           Pass option as an option to the linker.  If option contains commas,
           it is split into multiple options at the commas.  You can use this
           syntax to pass an argument to the option.  For example,
           -Wl,-Map,output.map passes -Map output.map to the linker.  When using
           the GNU linker, you can also get the same effect with
           -Wl,-Map=output.map.

           NOTE: In Ubuntu 8.10 and later versions, for LDFLAGS, the option
           -Wl,-z,relro is used.  To disable, use -Wl,-z,norelro.
-Wl,-rpath=《your_lib_dir》
-Wl
這個是gcc的參數,表示編譯器將後面的參數傳遞給鏈接器ld。
又比如gcc編譯怎樣指定特定的鏈接器?(未驗證)
-Wl,--dynamic-linker=/path/lib/ld-linux-x86-64.so.2


-rpath
使用man ld命令查看手冊,找到了-rpath的講解:
 Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The -rpath option is also used when locating shared objects which are needed by shared objects explicitly included in the link; see the description of the -rpath-link option. If -rpath is not used when linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will be used if it is defined.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章