GCC靜態編譯與動態編譯

靜態鏈接編譯

#  create a static library libvector.a
gcc -c addvec.c multvec.c
ar rcs libvector.a addvec.o multvec.o

# build the executable
gcc -c main2.c
gcc -static -o prog2c main2.o ./libvector.a
# or equivalently
gcc -static -o prog2c main2.o -L. -lvector

動態鏈接編譯

# build a shared library libvector.so 
# The -fpic flag directs the compiler to generate position-independent code. The -shared flag directs the linker to create a shared object file.
gcc -shared -fpic -o libvector.so addvec.c multvec.c

#  Once we have created the library, we would then link it into our example program
gcc -o prog2l main2.c ./libvector.so
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章