搜尋此網誌

網頁

2010年3月14日 星期日

GCC 編譯與連結

產生動態連結執行檔: gcc getarg.c writeinfo.c main.c -o test

產生靜態連結執行檔:
step1: gcc -c -o getarg.o getarg.c
gcc -c -o writeinfo.o writeinfo.c
gcc -c -o main.o main.c
step2:
gcc getarg.o writeinfo.o main.o -static -o test_static.o

執行檔檔案大小: test => 10798kb
test_static => 590326kb

靜態連結型執行檔對於嵌入式系統來說是不適用的,因此在系統支援動態的前提下,多採用動態連結方式使程式達到最佳化與省空間的目的。

實做動態連結庫:
gcc -shared getarg.o writeinfo.o -o libtest_d.so

連結動態庫產生可執行程式:
gcc main.o -L. -libtest_d.so -o test_dlib

修改環境變數:
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH <=目前仍無解 ./test_dlib



沒有留言:

張貼留言