ELF : executable and linkable format
四类 ELF : 可执行文件,object file, shared library, core dump

单个 source code 转 单个 object file
object file 静态链接转 static library(.a)
object file 动态链接转 dynamic/shared library(.so)

nm -Du :列出需要外界提供的 symbol
export LD_DEBUG=libs : 输出 library 查找过程
export LD_DEBUG=symbols : 输出 symbol 查找过程
LD_PRELOAD 环境变量:最先查找符号

编译时:

编译 so :
gcc -g -fPIC -c foo.c
gcc -shared foo.o -o libfoo.so

链接:
gcc -g -o main main.c libfoo.so
gcc -g -o main main.c -lfoo -L.
效果相同
-L{$DIR} : 查找 DIR 路径

real name : libX.so.A.B.C
soname : 软链接 libX.so.A -> libX.so.A.B.C
linker name : 软链接 libX.so -> libX.so.A
编译时 -soname (-Wl,-soname,libfoo.so.2) 选项使 ldconfig 时产生 soname 软链接

-Wl,-rpath,`pwd` # 编译时添加 rpath寻找路径

compiler : 程序转汇编
assembler : 汇编转机器码
linker : 把多个 object file 合成为单个 executable, library file 或 另一个 object file

标签: none

添加新评论