GNU 程式設計 -- 連結工具 ld 的用法

GNU 程式設計

GNU 程式簡介

GNU 與 C 語言

gcc 編譯器

glibc 函式庫

make 建置

ld 連結器

as 組譯器

ar 函式庫

objdump

objcopy

訊息

相關網站

參考文獻

最新修改

簡體版

English

GNU 的主要連結工具是 ld 指令, 但是在實務上, 通常我們會直接用 gcc 進行連結動作, 因為 gcc 會幫忙傳送給 ld 去執行, 表格一是 gcc 與 ld 連結時常用的參數表。

參數 範例 說明
-o <file> ld -o ab a.o b.o 連結 a.o, b.o 為執行檔 ab
-L <path> ld -o ab a.o b.o -L /home/lib 指定函式庫搜尋路徑為 /home/lib
-l<name> ld -o ab a.o b.o –lm 連結函式庫 lib<name>.a, 本範例連結的是 libm.a
-e <offset> ld -e 0x10000 -o hello crt0.o hello.o 設定連結啟始位址為 0x10000
-s ld -s -o ab a.o b.o 移除所有符號
-S ld -S -o ab a.o b.o 移除除錯符號
-r ld -r -o romfs.o romfs.img 輸出可重定位 (relocatable) 的檔案
-Map ld -o ab a.o b.o -Map ab.map 產生連結後的符號表
-T <linkscript> ld -o ab a.o b.o -T ab.ld 指定 link script 為 ab.ld
-T<段><位址> ld -o ab a.o b.o -Ttext 0x0 -Tdata 0x1000 -Tbss 0x3000 指定 text 段位址為 0x0 、data 段位址為 0x1000、bss 段位址為 0x3000

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License