gcc / -Wl
默認情況下,GCC / G++ 鏈接時優先鏈接動態庫,如果沒有動態庫,則鏈接相應的靜態庫。同時,GCC / G++ 也提供了鏈接選項 -Wl,-Bstatic 和 -Wl,-Bdynamic 供用戶指定鏈接動態庫或者靜態庫。
- -Wl,-Bstatic 指示跟在后面的 -lxxx 選項鏈接的都是靜態庫。
- -Wl,-Bdynamic 指示跟在后面的 -lxxx 選項鏈接的都是動態庫。
栗子:
-Wl,-Bstatic -llog4cplus -lpcap -lpgm -lxerces-c -Wl,-Bdynamic -lnl-3 -ldbus-1 -libverbs -lcurl -lhiredis -Wl,--as-needed
-Wl,-Bstatic 后面的庫是靜態鏈接的;? -Wl,-Bdynamic 后面的都是動態鏈接的。
原理上講,Wl 后面的東西是作為參數傳遞給鏈接器 ld 。
The -Wl,xxx option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So
"gcc -Wl,aaa,bbb,ccc"? eventually becomes a linker call "ld aaa bbb ccc"
轉載:GCC -Wl選項_wqfhenanxc的專欄-CSDN博客
(SAW:Game Over!)
總結
- 上一篇: shell / 获取当前工作目录的方法
- 下一篇: git / 通过 ssh 与仓库通信