静态链接在 编译时链接 a.out独立
动态链接在 运行时链接 不独立
静态库连接
1.c 静态库源文件 gcc -c 1.c
1.o 静态库目标文件
ar cr lib1.a 1.o 2.o
lib1.a 静态库
gcc 2.c lib1.a
(使用静态链接时只会链接 库中有引用的目标文件)
a.out 可执行文件
动态库链接
export LD_LIBRARY_PATH=/home/huan_24/huan24word/C/demo2
1.c 动态库源文件 gcc -c 1.c
1.o 动态库目标文件
gcc -fPIC -shared -o lib1.so 1.c
lib1.so 动态库
gcc 2.c lib1.so
a a.out 可执行文件