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
发布了21 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wzq2009/article/details/103454883
今日推荐